/* ==========================================================================
   screens.css — layout: the frame, the welcome screen, the desk (rail and
   pane), and the responsive steps.

   Layout answers to the app's own width through a container query, not the
   window's, so the same rules work full screen and inside the mockup's phone
   frame (docs/mockups/desk.html). Three steps:
     < 375px   narrow phones: tighter strip and header
     >= 560px  roomier phones and tablets: emoji in the strip, key hints
     >= 900px  desktop: the workspace rail appears and the pane is inset
   Only consumes tokens from tokens.css; no literal colours here.
   ========================================================================== */

.frame {
  container: app / inline-size;
  height: 100vh;
  height: 100dvh;
}

.app {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  background: var(--rail);
}

.screen {
  display: flex;
  flex: 1;
  min-height: 0;
}

/* ---- Welcome: an invite to the Compact --------------------------------- */

.screen-welcome {
  --ring: var(--surface);
  --icon-hover: var(--rail-hover);
  display: block;
  overflow-y: auto;
  overscroll-behavior: contain;
  color: var(--rail-text);
}

/* Grows with its content, so the backdrop inside covers the whole scroll. */
.welcome-inner {
  position: relative;
  isolation: isolate;
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

.welcome-backdrop {
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(70rem 42rem at 8% -12%, var(--glow-warm), transparent 62%),
    radial-gradient(56rem 44rem at 108% 112%, var(--glow-cool), transparent 60%),
    linear-gradient(180deg, var(--rail-top), var(--rail) 70%);
}

/* A faint field of wheat. */
.welcome-backdrop::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--rail-text);
  opacity: 0.045;
  -webkit-mask: var(--pattern-wheat) 0 0 / 72px 72px repeat;
  mask: var(--pattern-wheat) 0 0 / 72px 72px repeat;
}

.welcome-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(12px + var(--safe-top)) 12px 0 16px;
}

.welcome-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: var(--text-sm);
  font-weight: 800;
  letter-spacing: 0.01em;
}

.welcome-top .icon-btn { color: var(--rail-text); }

.welcome-main {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 28px;
  width: 100%;
  max-width: 74rem;
  margin: 0 auto;
  padding: 28px 16px calc(20px + var(--safe-bottom));
}

.welcome-hero {
  max-width: 34rem;
  text-align: center;
  animation: rise 560ms var(--ease-out) backwards;
}

.welcome-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px 5px 10px;
  border-radius: var(--radius-pill);
  background: var(--rail-hover);
  box-shadow: inset 0 0 0 1px var(--rail-line);
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--rail-muted);
}

.welcome-eyebrow::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent) 25%, transparent);
}

.welcome-title {
  margin-top: 16px;
  font-family: var(--font-display);
  font-size: clamp(2.5rem, 11cqi, 4rem);
  font-weight: 800;
  line-height: 0.98;
  letter-spacing: -0.035em;
  color: var(--hero-text);
  text-wrap: balance;
}

.welcome-title em { display: block; font-style: normal; color: var(--accent); }

.welcome-pitch {
  margin-top: 14px;
  font-size: var(--text-lg);
  line-height: 1.5;
  color: var(--rail-muted);
  text-wrap: balance;
}

.welcome-credit {
  margin-top: 18px;
  font-size: var(--text-xs);
  color: var(--rail-faint);
}

.invite {
  width: 100%;
  max-width: 27rem;
  overflow: clip;
  border-radius: var(--radius-2xl);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  animation: rise 620ms var(--ease-out) 90ms backwards;
}

.invite-banner {
  position: relative;
  height: 76px;
  background:
    radial-gradient(24rem 8rem at 20% 0%, var(--banner-sheen), transparent 70%),
    linear-gradient(120deg, var(--brand-from), var(--brand-to) 60%, var(--brand-deep));
}

.invite-banner::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--brand-ink);
  opacity: 0.14;
  -webkit-mask: var(--pattern-wheat) 0 0 / 72px 72px repeat;
  mask: var(--pattern-wheat) 0 0 / 72px 72px repeat;
}

.invite-head {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 24px 18px;
  text-align: center;
}

.invite-head .brand-mark {
  margin-top: -34px;
  box-shadow:
    0 0 0 5px var(--surface),
    var(--shadow-mark-lifted);
}

.invite-kicker {
  margin-top: 12px;
  font-size: var(--text-sm);
  color: var(--text-muted);
}

.invite-name {
  margin-top: 2px;
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.025em;
}

.invite-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 16px;
  margin-top: 8px;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-muted);
}

.invite-meta span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.invite-meta span::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-faint);
}

.invite-meta .is-online::before { background: var(--presence-online); }

.invite-body {
  padding: 4px 12px 0;
  border-top: 1px solid var(--border);
}

.invite-label {
  padding: 14px 12px 4px;
  font-size: var(--text-2xs);
  font-weight: 800;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.invite-actions {
  position: sticky;
  bottom: 0;
  padding: 14px 24px 22px;
  background: linear-gradient(to bottom, color-mix(in oklab, var(--surface) 0%, transparent), var(--surface) 24px);
}

/* ---- The desk ---------------------------------------------------------- */

.screen-desk {
  background: linear-gradient(180deg, var(--rail-top), var(--rail) 36%);
}

.rail { display: none; }

.pane {
  position: relative;
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
  background: var(--surface);
}

.pane-head {
  position: relative;
  z-index: 2;
  flex: none;
}

.topbar {
  --topbar-bg: var(--rail);
  --topbar-text: var(--rail-text);
  --topbar-muted: var(--rail-muted);
  --ring: var(--topbar-bg);
  --icon-hover: var(--rail-hover);
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 56px;
  padding: calc(8px + var(--safe-top)) 8px 8px 16px;
  background: var(--topbar-bg);
  color: var(--topbar-text);
}

.channel {
  flex: 1;
  min-width: 0;
}

.channel-name {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: var(--text-base);
  font-weight: 800;
  letter-spacing: -0.01em;
  line-height: 1.25;
}

.channel-name .i {
  width: 16px;
  height: 16px;
  stroke-width: 2.4;
  color: var(--topbar-muted);
}

.channel-topic {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: var(--text-xs);
  line-height: 1.35;
  color: var(--topbar-muted);
  font-variant-numeric: tabular-nums;
}

.channel-topic b { font-weight: 700; color: var(--topbar-text); }

.topbar .icon-btn { color: var(--topbar-text); }

.strip-wrap {
  padding: 10px 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.feed {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-mask-image: var(--scroll-fade);
  mask-image: var(--scroll-fade);
}

/* Messages sit at the bottom, near the replies, like any chat. */
.exchange {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  padding: 12px 0 10px;
}

.exchange > :first-child { margin-top: auto; }

.exchange.is-leaving {
  pointer-events: none;
  animation: leave var(--dur) var(--ease-out) forwards;
}

.composer {
  flex: none;
  padding: 0 8px var(--safe-bottom);
  background: var(--surface);
}

/* ---- Rail (wide screens) ----------------------------------------------- */

.rail-head {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 64px;
  padding: 14px 16px 10px;
}

.rail-workspace {
  font-size: var(--text-md);
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: -0.005em;
}

.rail-sub { font-size: var(--text-xs); color: var(--rail-muted); }

.rail-body {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 22px;
  min-height: 0;
  padding: 6px 8px 14px;
  overflow-y: auto;
}

.rail-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
  padding: 0 8px;
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--rail-muted);
}

.rail-count { font-weight: 600; color: var(--rail-faint); }

.term {
  margin: 0 2px;
  padding: 11px 12px 12px;
  border-radius: var(--radius-md);
  background: var(--rail-hover);
  box-shadow: inset 0 0 0 1px var(--rail-line);
}

.term-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 9px;
  font-size: var(--text-xs);
  color: var(--rail-muted);
  font-variant-numeric: tabular-nums;
}

.term-head b {
  font-size: var(--text-md);
  font-weight: 800;
  color: var(--rail-text);
}

.term-track {
  display: grid;
  grid-template-columns: repeat(20, minmax(0, 1fr));
  gap: 3px;
}

.term-seg {
  height: 6px;
  border-radius: 2px;
  background: var(--term-empty);
  transition: background-color var(--dur-slow) ease;
}

.term-seg.is-done { background: var(--accent); }
.term-seg.is-now { background: color-mix(in oklab, var(--accent) 45%, transparent); box-shadow: inset 0 0 0 1px var(--accent); }

.channel-link {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  padding: 0 8px;
  border-radius: var(--radius-md);
  font-size: var(--text-md);
  color: var(--rail-muted);
  text-decoration: none;
}

.channel-link .i { width: 16px; height: 16px; stroke-width: 2.4; }

.channel-link.is-active {
  background: var(--rail-active);
  color: var(--rail-text);
  font-weight: 700;
}

/* Flush with the window's left and bottom edges; on the right it keeps the
   same gutter as the pane and rounds off to match it. */
.rail-foot {
  --ring: var(--rail-sunken);
  --icon-hover: var(--rail-hover);
  display: flex;
  align-items: center;
  gap: 10px;
  margin-right: var(--pane-inset);
  padding: 10px 10px 10px 14px;
  border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
  background: var(--rail-sunken);
}

.rail-foot .avatar { --size: 32px; }
.me-name { font-size: var(--text-sm); font-weight: 800; line-height: 1.25; }
.me-status { font-size: var(--text-xs); line-height: 1.25; color: var(--rail-muted); }
.rail-foot .icon-btn { margin-left: auto; color: var(--rail-muted); }

/* ---- Narrow phones ------------------------------------------------------ */

@container app (max-width: 374px) {
  .topbar { gap: 8px; padding-left: 14px; }
  .facepile { gap: 4px; padding: 0; }
  .facepile .avatar { --size: 22px; }
  .channel-topic { font-size: var(--text-2xs); }
  .strip { gap: 4px; }
  .metric { padding: 7px 6px 8px; }
  .metric-label { font-size: 0.625rem; }
  .metric-number { font-size: 1.125rem; }
}

/* ---- Roomier phones and small tablets ---------------------------------- */

@container app (min-width: 560px) {
  .metric-emoji { display: inline; }
  .metric {
    grid-template-areas:
      "top   eye"
      "value value"
      "bar   bar";
  }
  .metric-eye .i { width: 15px; height: 15px; }
  .strip-wrap { padding: 12px 16px 14px; }
  .strip { gap: 8px; }
  .metric { padding: 10px 12px 11px; }
  .metric-number { font-size: 1.5rem; }
  .msg { padding-inline: 20px; }
  .system { padding-inline: 20px; }
  .divider { margin-inline: 20px; }
  .composer { padding: 0 16px calc(4px + var(--safe-bottom)); }
  .composer-hint { display: flex; }
}

/* ---- Desktop: rail + inset pane ---------------------------------------- */

@container app (min-width: 900px) {
  .rail {
    display: flex;
    flex: none;
    flex-direction: column;
    width: var(--rail-width);
    min-height: 0;
    color: var(--rail-text);
  }

  .pane {
    margin: var(--pane-inset) var(--pane-inset) var(--pane-inset) 0;
    overflow: hidden;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-pane);
  }

  .topbar {
    --topbar-bg: var(--surface);
    --topbar-text: var(--text);
    --topbar-muted: var(--text-muted);
    --icon-hover: var(--surface-2);
    min-height: 60px;
    padding: 10px 16px 10px 20px;
    border-bottom: 1px solid var(--border);
  }

  .channel {
    display: flex;
    align-items: center;
    gap: 12px;
  }

  .channel-name { flex: none; font-size: var(--text-lg); }

  .channel-topic {
    padding-left: 12px;
    border-left: 1px solid var(--border-strong);
    font-size: var(--text-sm);
  }

  .topbar .theme-toggle { display: none; }

  .strip-wrap { padding: 14px 20px 16px; }

  .welcome-main {
    flex-direction: row;
    gap: clamp(40px, 7cqi, 112px);
    padding: 32px 48px 48px;
  }

  .welcome-hero {
    flex: 1;
    max-width: 38rem;
    text-align: left;
  }

  .welcome-title { font-size: clamp(3.5rem, 5.6cqi, 5.25rem); }
  .welcome-pitch { font-size: var(--text-xl); }
  .invite { flex: none; width: 27rem; }
}
