/* The Backstage shell (sections 3.0.2 to 3.0.4). Phone first: a 52 px header (the menu button, the
   area's name, its tools) and the area's content; the menu button opens the side panel with every area
   (batch n1). Detail screens swap the header for one 52 px back bar. From 720 px a sidebar (64 px of
   icons, 232 px from 1100) and a list column beside the detail. Backstage never draws a bottom tab bar:
   inside the app, the app's own tab bar sits below the frame. */

.app {
  display: flex;
  height: 100vh;
  height: 100dvh;
  background: var(--canvas);
}
.stage {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding-top: var(--top-space);
}

/* ---------- Phone header ---------- */
.top {
  flex: none;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  padding: 0 4px 0 var(--pad);
  border-bottom: 1px solid var(--line);
}
.top:has(.menu-btn) {
  padding-left: 4px;
}
.menu-btn {
  position: relative;
  color: var(--ink);
}
.menu-btn .menu-badge {
  position: absolute;
  top: 0;
  right: -2px;
  min-width: 22px;
  height: 22px;
  padding: 0 5px;
  border: 2px solid var(--canvas);
  font-size: 13px;
  line-height: 18px;
}
.top-title {
  flex: 1;
  min-width: 0;
  padding-left: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font: 600 17px/1.2 var(--sans);
  color: var(--ink);
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font: 600 15px var(--sans);
  color: var(--ink);
}
.brand .icon {
  width: 20px;
  height: 20px;
  color: var(--jade);
}
.tools {
  display: flex;
  align-items: center;
}
/* An area may have two tools (New chat, Earlier chats): they sit in a row, never stacked. */
.area-tools {
  display: flex;
  align-items: center;
}
.icon-btn {
  width: var(--tap);
  height: var(--tap);
  flex: none;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 12px;
  background: none;
  color: var(--ink-soft);
  text-decoration: none;
}
.icon-btn .icon {
  width: 22px;
  height: 22px;
}
@media (hover: hover) {
  .icon-btn:hover {
    color: var(--ink);
  }
  .side-link:hover {
    background: var(--inset);
  }
}
.icon-btn[aria-current],
.icon-btn[aria-expanded="true"] {
  color: var(--jade-deep);
}
.badge {
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 11px;
  background: var(--jade);
  color: #fff;
  font: 600 13px/22px var(--sans);
  text-align: center;
  font-variant-numeric: lining-nums tabular-nums;
}

/* ---------- Detail bar (phone) ---------- */
.dbar {
  flex: none;
  height: 52px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 4px;
  border-bottom: 1px solid var(--line);
}
.dbar-back,
.top-back {
  justify-self: start;
  display: flex;
  align-items: center;
  gap: 2px;
  height: var(--tap);
  min-width: var(--tap);
  padding: 0 8px 0 4px;
  color: var(--jade-deep);
  font: 500 16px var(--sans);
  text-decoration: none;
  white-space: nowrap;
}
.dbar-back .icon,
.top-back .icon {
  width: 20px;
  height: 20px;
}
.dbar-label {
  min-width: 0;
  max-width: 190px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font: 600 15px var(--sans);
  text-align: center;
}
.dbar-right {
  justify-self: end;
  display: flex;
}

/* ---------- Strips ---------- */
.offline {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 6px var(--pad);
  background: var(--clay-soft);
  color: var(--clay-ink);
  font-size: var(--text-2);
}
.offline .icon {
  width: 18px;
  height: 18px;
  flex: none;
}

/* ---------- Columns ---------- */
.cols {
  flex: 1;
  min-height: 0;
  display: flex;
}
.col {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.col-head,
.detail-head {
  display: none;
}
.col-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px var(--pad) calc(24px + var(--bottom-space));
}
.col-body:focus {
  outline: none;
}
.col-foot {
  flex: none;
  padding-bottom: var(--bottom-space);
  background: var(--bar);
  border-top: 1px solid var(--line);
}
.search-row {
  flex: none;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 4px 2px var(--pad);
}
.search-row .field {
  flex: 1;
  min-width: 0;
}
/* A refresh behind a screen drawn from kept answers failed (or just worked again): one quiet line. */
.stale-line {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: var(--tap);
  margin: 0;
  padding: 0 4px 0 var(--pad);
  border-bottom: 1px solid var(--line);
  color: var(--ink-soft);
  font-size: var(--text-2);
}
.stale-line[hidden] {
  display: none;
}
.stale-line[data-state="updated"] {
  color: var(--fern);
}
.pick {
  height: 100%;
  min-height: 200px;
  display: grid;
  place-items: center;
  color: var(--ink-soft);
  font-size: var(--text);
}

/* Phone: one column at a time. */
.app[data-view="list"] .dbar,
.app[data-view="list"] .col-detail,
.app[data-view="detail"] .top,
.app[data-view="detail"] .col-list {
  display: none;
}

/* ---------- The Tile studio's frame (areas/studio.js, look in css/studio.css) ----------
   It sits beside the columns so drawing an area never touches it. Away from the studio it keeps its
   size but is not painted, not tappable and inert, so the studio loaded ahead lays out as it will show. */
.cols {
  position: relative;
}
.studio-host {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  visibility: hidden;
  pointer-events: none;
  background: var(--canvas);
}
.app[data-area="studio"] .cols > .col,
.app[data-area="studio"][data-view] .cols > .col {
  display: none;
}
.app[data-area="studio"] .studio-host {
  position: static;
  flex: 1;
  min-width: 0;
  visibility: visible;
  pointer-events: auto;
}

/* ---------- Sidebar (720 px and up) ---------- */
.sidebar {
  display: none;
}
@media (min-width: 720px) {
  .sidebar {
    flex: none;
    width: 64px;
    display: flex;
    flex-direction: column;
    /* 64 px less the 1 px line and 9 px each side leaves 45 px: room for 44 px targets. */
    padding: 18px 9px 16px;
    border-right: 1px solid var(--line);
    background: var(--canvas);
  }
  .stage {
    padding-top: 0;
  }
  .top,
  .dbar,
  .app[data-view] .top,
  .app[data-view] .dbar,
  .drawer {
    display: none;
  }
  .app[data-view] .col-list,
  .app[data-view] .col-detail {
    display: flex;
  }
  .app[data-layout="single"] .col-detail {
    display: none;
  }
  .col-list {
    flex: none;
    width: clamp(300px, 36vw, 400px);
    border-right: 1px solid var(--line);
  }
  .app[data-layout="single"] .col-list {
    flex: 1;
    width: auto;
    border-right: 0;
  }
  .col-head {
    flex: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-height: 72px;
    padding: 18px 12px 4px 20px;
  }
  .col-title {
    font-size: 34px;
  }
  .head-back {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    height: var(--tap);
    margin-left: -6px;
    color: var(--jade-deep);
    font: 500 15px var(--sans);
    text-decoration: none;
  }
  .head-back .icon {
    width: 18px;
    height: 18px;
  }
  .col-list .col-body {
    padding: 6px 20px 24px;
  }
  .app[data-layout="single"] .col-list .col-head,
  .app[data-layout="single"] .col-list .col-body {
    padding-left: 32px;
    padding-right: 32px;
  }
  .search-row {
    padding: 4px 12px 2px 20px;
  }
  .stale-line {
    padding-left: 20px;
  }
  .app[data-layout="single"] .stale-line,
  .col-detail .stale-line {
    padding-left: 32px;
  }
  .detail-head {
    flex: none;
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 62px;
    padding: 14px 20px 0 32px;
  }
  .detail-head:empty {
    min-height: 0;
    padding: 0;
  }
  .detail-head .dh-label {
    flex: 1;
    min-width: 0;
  }
  .col-detail .col-body {
    padding: 14px 32px 32px;
  }
  /* No head strip: the page's own title lines up with the list column's title. */
  .detail-head:empty + .col-body {
    padding-top: 26px;
  }
}
@media (min-width: 1100px) {
  .sidebar {
    width: 232px;
    padding: 22px 14px 16px;
  }
}

.wordmark {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  color: var(--ink);
  text-decoration: none;
}
.wm-full {
  display: none;
}
.wm-key {
  width: var(--tap);
  height: var(--tap);
  display: grid;
  place-items: center;
  color: var(--jade);
}
.wm-key .icon {
  width: 22px;
  height: 22px;
}
.side-nav {
  margin-top: 22px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.side-link {
  position: relative;
  height: var(--tap);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  border-radius: 10px;
  color: var(--ink-soft);
  font: 500 16px var(--sans);
  text-decoration: none;
}
.side-link .icon {
  width: 21px;
  height: 21px;
  flex: none;
}
.side-link[aria-current] {
  background: var(--jade-soft);
  color: var(--jade-ink);
  font-weight: 600;
}
/* The Tile studio stands apart: its icon in a filled chip, its name in the primary color. */
.side-chip {
  width: 32px;
  height: 32px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 9px;
  background: var(--jade);
  color: #fff;
}
.side-link.featured .side-chip .icon {
  width: 20px;
  height: 20px;
}
.side-link.featured {
  color: var(--jade-deep);
  font-weight: 600;
}
.side-label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
.side-link .badge {
  position: absolute;
  top: 3px;
  right: 3px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  font-size: 13px;
  line-height: 20px;
}
.side-foot {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.side-who {
  display: none;
}
@media (min-width: 1100px) {
  .wordmark {
    justify-content: flex-start;
    padding: 0 10px;
  }
  .wm-full {
    display: block;
  }
  .wm-key {
    display: none;
  }
  .wm-name {
    display: block;
    font: 600 25px/1.1 var(--display);
  }
  .wm-name b {
    color: var(--jade);
    font-weight: 600;
  }
  .wordmark small {
    display: block;
    margin-top: 3px;
    font: 600 12px var(--sans);
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--jade-deep);
  }
  .side-nav {
    margin-top: 26px;
  }
  .side-link {
    justify-content: flex-start;
    padding: 0 12px;
  }
  .side-link.featured {
    height: 52px;
    margin: 4px 0;
    padding-left: 6px;
    gap: 10px;
    border: 1px solid var(--line);
    background: var(--paper);
  }
  .side-link.featured[aria-current] {
    border-color: var(--jade);
    background: var(--jade-soft);
  }
  .side-label {
    position: static;
    width: auto;
    height: auto;
    overflow: visible;
    clip: auto;
  }
  .side-link .badge {
    position: static;
    margin-left: auto;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    line-height: 22px;
  }
  .side-who {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 0 0 12px;
    font-size: var(--text-2);
    color: var(--ink-soft);
  }
  /* Assistant's look (loaded once it opens) has its own .who-name: the shell's keeps its size. */
  .side-who .who-name {
    min-width: 0;
    font-size: inherit;
    font-weight: 400;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}
.signout {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
  padding: 0 12px;
  color: var(--jade-deep);
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}
html.embed .signout {
  display: none;
}

/* ---------- Sign-in, signed out and boot (section 3.13) ---------- */
.gate {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: calc(24px + var(--top-space)) var(--pad) calc(24px + var(--bottom-space));
}
.gate-card {
  width: 100%;
  max-width: 400px;
  padding: 32px 24px 28px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  text-align: center;
}
.gate-card img {
  display: block;
  width: 72px;
  height: 72px;
  margin: 0 auto 14px;
  border-radius: 16px;
}
.gate-card h1 {
  font-size: 32px;
}
.gate-card p {
  margin-top: 8px;
  color: var(--ink-soft);
}
.gate-card .btn {
  margin-top: 22px;
}
.gate-card .fine {
  margin-top: 14px;
  font-size: var(--text-meta);
}
.ms-logo {
  width: 18px;
  height: 18px;
  flex: none;
}

/* ---------- The side panel (phones, lib/drawer.js) ----------
   From the left over a scrim, the whole frame's height inside the safe areas. --shown (0 to 1) is set
   while a finger drags it, so the scrim follows. */
.drawer {
  position: fixed;
  inset: 0;
  z-index: 35;
}
.drawer-scrim {
  position: absolute;
  inset: 0;
  background: rgba(46, 33, 26, 0.42);
  opacity: 0;
  transition: opacity 0.28s ease;
  touch-action: none;
}
.drawer.open .drawer-scrim {
  opacity: 1;
}
.drawer.dragging .drawer-scrim {
  opacity: var(--shown, 0);
  transition: none;
}
.drawer-panel {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: min(84vw, 320px);
  display: flex;
  flex-direction: column;
  padding: calc(14px + var(--top-space)) 10px calc(10px + var(--bottom-space));
  background: var(--canvas);
  box-shadow: 0 0 32px rgba(46, 33, 26, 0.18);
  transform: translateX(-100%);
  transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
  touch-action: pan-y;
  overscroll-behavior: contain;
}
.drawer.open .drawer-panel {
  transform: translateX(0);
}
.drawer.dragging .drawer-panel {
  transition: none;
}
.drawer-head {
  padding: 4px 12px 14px;
}
.drawer-head .wm-name {
  display: block;
  font: 600 24px/1.1 var(--display);
  color: var(--ink);
}
.drawer-head .wm-name b {
  color: var(--jade);
  font-weight: 600;
}
.drawer-head small {
  display: block;
  margin-top: 3px;
  font: 600 12px var(--sans);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--jade-deep);
}
.drawer-nav {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.drawer-link {
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 12px;
  border-radius: 12px;
  color: var(--ink);
  font: 500 17px var(--sans);
  text-decoration: none;
}
.drawer-link > .icon {
  width: 22px;
  height: 22px;
  flex: none;
  color: var(--ink-soft);
}
.drawer-link .dl-label {
  flex: 1;
  min-width: 0;
}
.drawer-link .badge {
  flex: none;
}
.drawer-link[aria-current] {
  background: var(--jade-soft);
  color: var(--jade-ink);
  font-weight: 600;
}
.drawer-link[aria-current] > .icon {
  color: var(--jade-deep);
}
.drawer-link:active {
  background: var(--inset);
}
/* The Tile studio, featured: a card row with its tile icon in a filled chip and a line under the name. */
.drawer-link.featured {
  min-height: 64px;
  margin: 6px 0;
  padding: 8px 12px 8px 8px;
  gap: 12px;
  border: 1px solid var(--line);
  background: var(--paper);
}
.drawer-link.featured[aria-current] {
  border-color: var(--jade);
  background: var(--jade-soft);
}
.dl-chip {
  width: 44px;
  height: 44px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 11px;
  background: var(--jade);
  color: #fff;
}
.dl-chip .icon {
  width: 24px;
  height: 24px;
}
.dl-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.drawer-link.featured .dl-label {
  font-weight: 600;
  color: var(--jade-deep);
}
.dl-line {
  font: 400 var(--text-meta) / 1.3 var(--sans);
  color: var(--ink-soft);
}
.drawer-foot {
  flex: none;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}
.drawer-who {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: var(--tap);
  padding-left: 12px;
  font-size: var(--text-2);
  color: var(--ink-soft);
}
.drawer-who .who-name {
  min-width: 0;
  font-size: inherit;
  font-weight: 400;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
@media (prefers-reduced-motion: reduce) {
  .drawer-panel,
  .drawer-scrim {
    transition: none;
  }
}

/* ---------- Home and the way back to it (Pat, 2026-11-06) ----------
   Home lists every area, the way the app's You page lists Your progress and Badges, so a phone no
   longer opens a side panel: each area's own screen has "Backstage" at the left to go back to Home,
   the area's name in the middle and its tools at the right, like the detail bar. */
.menu-btn {
  display: none;
}
.top {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  padding: 0 4px;
}
.top .top-title {
  padding: 0;
  max-width: 190px;
  text-align: center;
  font-size: 15px;
}
.top .tools {
  justify-self: end;
}
.app[data-area="home"] .top {
  grid-template-columns: 1fr auto;
  padding-left: var(--pad);
}
.app[data-area="home"] .top-back {
  display: none;
}
.app[data-area="home"] .top .top-title {
  max-width: none;
  text-align: left;
  font-size: 17px;
}
