/* Crew Builder components. Load tokens.css first.
   Sections: base, shell, 1 icon rail, 2 crew list, 3 character stage, 3b middle views, 4 chat,
   then the laptop and phone breakpoints. Values match the Round 4 style guide exactly. */

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font: 14px/1.5 var(--f-body);
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--signal); outline-offset: 2px; }

/* App shell: one white window centred on the grey ground, 24px of ground on every side.
   Each column scrolls inside itself; the window never grows. */
.shell {
  min-height: 100%;
  padding: 24px;
  display: grid; place-items: center;
}
.app {
  width: min(1380px, 100vw - 48px);
  height: clamp(680px, 100vh - 48px, 900px);
  background: var(--win);
  border-radius: 28px;
  box-shadow: var(--shadow-win);
  display: grid;
  grid-template-columns: 76px 272px minmax(0, 1fr) 392px;
  grid-template-rows: minmax(0, 1fr);
  overflow: hidden;
}

/* 1. Icon rail */
.rail {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 22px 0 18px;
  border-right: 1px solid var(--hair);
}
.logo { margin-bottom: 18px; color: var(--ink); }
.pill {
  width: 42px; height: 42px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--win); border: 1px solid var(--hair-2); color: var(--ink-2);
  position: relative;
}
.pill[aria-current="page"] { background: var(--ink); border-color: var(--ink); color: var(--on-ink); }
.pill .dot { position: absolute; top: 1px; right: 1px; width: 9px; height: 9px; border-radius: 50%; background: var(--signal); border: 2px solid var(--win); }
.rail .spacer { flex: 1; }
.navi { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.pill-l { font-size: 10.5px; color: var(--muted); line-height: 1; }
.navi:has([aria-current="page"]) .pill-l { color: var(--ink); font-weight: 500; }
@media (max-width: 899px) {
  body.cb .navi:has(.b2) { display: none; }
}
.rail { gap: 12px; }
.hint { font-size: 12px; color: var(--muted); line-height: 1.4; }
.me { width: 38px; height: 38px; border-radius: 50%; background: var(--sunk-2); display: grid; place-items: center; font: 500 13px var(--f-display); }

/* 2. Crew list */
.list { border-right: 1px solid var(--hair); display: flex; flex-direction: column; min-width: 0; overflow-y: auto; }
.list-h { padding: 24px 20px 6px; display: flex; justify-content: space-between; align-items: baseline; }
.list-h h1 { margin: 0; font: 500 22px var(--f-display); letter-spacing: -.01em; }
.list-hint { margin: 0; padding: 0 20px 12px; }
.list-h span { font: 400 11.5px var(--f-mono); color: var(--muted); }
.group { padding: 4px 10px 14px; display: flex; flex-direction: column; gap: 2px; }
.group-label { padding: 8px 10px 6px; font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; }
.row {
  display: grid; grid-template-columns: 40px minmax(0,1fr) auto; gap: 10px; align-items: center;
  padding: 9px 10px; border-radius: 14px; border: 0; background: none; text-align: left; width: 100%;
}
.row:hover { background: var(--sunk); }
.row[aria-selected="true"] { background: var(--sunk-2); }
.row .face { width: 40px; height: 40px; border-radius: 13px; background: var(--sunk); }
.row[aria-selected="true"] .face { background: var(--win); }
.row b { display: block; font-weight: 500; font-size: 14px; }
.row small { display: block; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; font: 400 11px var(--f-mono); color: var(--muted); font-variant-numeric: tabular-nums; }
.blip { width: 7px; height: 7px; border-radius: 50%; background: var(--signal); animation: pulse 1.6s ease-in-out infinite; }
.blip.off { background: var(--hair-2); animation: none; }
.divider { height: 1px; background: var(--hair); margin: 4px 20px 6px; }
.need {
  display: flex; flex-direction: column; gap: 4px; padding: 11px 12px; border-radius: 14px;
  border: 1px solid var(--hair); background: var(--win); text-align: left; width: 100%;
}
.need:hover { border-color: var(--hair-2); }
.need-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.need b { font-weight: 500; font-size: 13.5px; }
.need small { color: var(--muted); font-size: 12px; }
.badge { font: 500 10px var(--f-mono); letter-spacing: .06em; text-transform: uppercase; padding: 3px 8px; border-radius: 999px; white-space: nowrap; }
.badge.sig { background: var(--signal-soft); color: var(--signal); }
.badge.plain { background: var(--sunk-2); color: var(--ink-2); }
.list-foot { margin-top: auto; padding: 14px 20px 20px; }
.spend { background: var(--sunk); border-radius: 16px; padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.spend-top { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--muted); }
.spend b { font: 300 24px/1 var(--f-display); color: var(--ink); letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.spend b small { font-size: 13px; color: var(--muted); }
.switch { width: 32px; height: 19px; border-radius: 999px; background: var(--ink); position: relative; border: 0; padding: 0; flex: none; }
.switch::after { content: ""; position: absolute; top: 3px; left: 16px; width: 13px; height: 13px; border-radius: 50%; background: var(--win); transition: left .15s; }
.switch[aria-checked="false"] { background: var(--signal); }
.switch[aria-checked="false"]::after { left: 3px; }
.track { height: 4px; border-radius: 4px; background: var(--sunk-2); overflow: hidden; }
.track i { display: block; height: 100%; background: var(--ink); border-radius: 4px; }

/* 3. Character stage */
.stage {
  background: var(--sunk);
  display: grid; grid-template-rows: auto minmax(0, 1fr) auto; grid-template-columns: minmax(0, 1fr);
  min-width: 0; position: relative;
}
.stage-top { padding: 20px 24px 0; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.live {
  display: inline-flex; align-items: center; gap: 10px;
  background: var(--win); border-radius: 999px; padding: 7px 14px 7px 10px;
  box-shadow: var(--shadow-pop); font-size: 13px; min-width: 0;
}
.live .tagl { display: inline-flex; align-items: center; gap: 6px; font: 500 10.5px var(--f-mono); letter-spacing: .08em; color: var(--signal); text-transform: uppercase; flex: none; }
.live .tagl i { width: 6px; height: 6px; border-radius: 50%; background: var(--signal); animation: pulse 1.6s ease-in-out infinite; }
.live.idle .tagl { color: var(--muted); }
.live.idle .tagl i { background: var(--muted); animation: none; }
.live .what { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.wave { display: inline-flex; gap: 2px; align-items: center; height: 12px; flex: none; }
.wave span { width: 2px; height: 100%; border-radius: 1px; background: var(--signal); animation: wave 1.1s ease-in-out infinite; }
.wave span:nth-child(2){animation-delay:.15s}.wave span:nth-child(3){animation-delay:.3s}.wave span:nth-child(4){animation-delay:.45s}
.live.idle .wave { display: none; }
.rank { font: 400 12px var(--f-mono); color: var(--muted); white-space: nowrap; }

.figure { display: grid; grid-template-columns: 44px minmax(0,1fr) 44px; align-items: center; padding: 8px 20px; min-height: 0; overflow: hidden; grid-template-rows: minmax(0, 1fr); }
.arrow { width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--hair-2); background: var(--win); display: grid; place-items: center; color: var(--ink-2); }
.portrait { display: flex; justify-content: center; align-items: center; min-height: 0; align-self: stretch; }
#big { height: min(100%, 330px); width: auto; aspect-ratio: 1; max-width: 100%; display: block; }
#big circle.t { transform-box: fill-box; transform-origin: center; }
.working #big circle.t { animation: breathe 2.6s ease-in-out infinite; }

.card {
  margin: 0 24px 24px; background: var(--win); border-radius: 24px; padding: 22px 24px;
  box-shadow: var(--shadow-pop);
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 18px 28px; align-items: end;
}
.who h2 { margin: 0; font: 300 46px/1 var(--f-display); letter-spacing: -.035em; }
.who .meta { margin-top: 6px; font-size: 12.5px; color: var(--muted); }
.who p { margin: 10px 0 0; color: var(--ink-2); font-size: 14px; max-width: 42ch; }
.score { text-align: right; }
.score b { font: 200 46px/1 var(--f-display); letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.score b small { font-size: 16px; color: var(--muted); font-weight: 300; }
.score span { display: block; font-size: 12px; color: var(--muted); margin-top: 4px; }
.level { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 8px; }
.level-top { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; font-size: 13px; }
.level-top b { font: 500 15px var(--f-display); }
.level-top span { font: 400 12px var(--f-mono); color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; min-width: 0; }
.level-top span em { font-style: normal; color: var(--ink); }
.xp { height: 8px; border-radius: 8px; background: var(--sunk-2); overflow: hidden; position: relative; }
.xp i { position: absolute; inset: 0 auto 0 0; border-radius: 8px; background: var(--ink); }
.xp i::after { content: ""; position: absolute; right: 0; top: 0; bottom: 0; width: 8px; border-radius: 8px; background: var(--signal); }
.chips { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--hair-2); font-size: 12.5px; color: var(--ink-2); background: var(--win); }
.chip.job { background: var(--sunk); border-color: transparent; color: var(--ink); }

/* 3b. Other views that take the middle space */
.pane { background: var(--sunk); min-width: 0; overflow-y: auto; padding: 28px; display: flex; flex-direction: column; gap: 22px; }
.pane-h { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; }
.pane-h h2 { margin: 0; font: 300 46px/1 var(--f-display); letter-spacing: -.035em; }
.pane-h p { margin: 10px 0 0; color: var(--ink-2); max-width: 46ch; font-size: 14px; }
.pane-h .btn { flex: none; }
.sec { display: flex; flex-direction: column; gap: 8px; }
.sec-l { font-size: 12px; color: var(--muted); padding-left: 4px; display: flex; justify-content: space-between; }
.sheet { background: var(--win); border-radius: 22px; box-shadow: var(--shadow-pop); padding: 4px 20px; }
.r { display: grid; align-items: center; gap: 14px; padding: 14px 0; border-bottom: 1px solid var(--hair); }
.r:last-child { border-bottom: 0; }
.r b { font-weight: 500; font-size: 14px; }
.r small { display: block; color: var(--muted); font-size: 12px; }
.r.job { grid-template-columns: minmax(0,1fr) auto auto; }
.r.job .holder { min-width: 132px; }
.r.lead { grid-template-columns: 22px 40px minmax(0,1fr) auto 46px; }
.r.verdict-r { grid-template-columns: minmax(0,1fr) auto auto; }
.r.ver { grid-template-columns: auto minmax(0,1fr) auto; }
.r.prov { grid-template-columns: 36px minmax(0,1fr) auto auto; }
.mono { font: 400 12.5px var(--f-mono); color: var(--ink-2); white-space: nowrap; font-variant-numeric: tabular-nums; }
.holder { display: flex; align-items: center; justify-content: flex-end; gap: 8px; font-size: 13px; }
.holder svg, .r .f { width: 28px; height: 28px; border-radius: 9px; background: var(--sunk); flex: none; }
.r.lead .f { width: 40px; height: 40px; border-radius: 13px; }
.holder .vs { color: var(--muted); font-size: 11px; }
.rk { font: 500 12px var(--f-mono); color: var(--muted); }
.ring { width: 46px; height: 46px; display: block; }
.ring text { font: 500 13px var(--f-display); fill: var(--ink); }
.you { font-size: 12px; color: var(--muted); white-space: nowrap; }
.you.agree { color: var(--good); }
.you.over { color: var(--signal); }
.faces { display: flex; width: 96px; }
.faces svg { width: 30px; height: 30px; border-radius: 10px; background: var(--sunk); border: 2px solid var(--win); margin-left: -8px; }
.faces svg:first-child { margin-left: 0; }
.judgecard { display: grid; grid-template-columns: 64px minmax(0,1fr); gap: 16px; align-items: center; background: var(--win); border-radius: 22px; box-shadow: var(--shadow-pop); padding: 16px 20px; }
.judgecard svg { width: 64px; height: 64px; border-radius: 20px; background: var(--sunk); }
.judgecard p { margin: 4px 0 0; color: var(--ink-2); font-size: 13px; }
.logo-b { width: 36px; height: 36px; border-radius: 12px; background: var(--sunk); display: grid; place-items: center; font: 600 13px var(--f-display); }
.ok-t { font-size: 12px; color: var(--good); white-space: nowrap; }
@media (max-width: 899px) {
  body.cb .pane { padding: 18px 14px; }
  body.cb .pane-h { flex-direction: column; align-items: flex-start; }
  body.cb .pane-h h2 { font-size: 38px; }
  body.cb .r.job { grid-template-columns: minmax(0,1fr) auto; }
  body.cb .r.job .mono { grid-column: 1; grid-row: 2; margin-top: -10px; }
  body.cb .r.job .holder { grid-column: 2; grid-row: 1 / span 2; }
  body.cb .r.lead { grid-template-columns: 40px minmax(0,1fr) 46px; }
  body.cb .r.lead .rk, body.cb .r.lead .mono { display: none; }
  body.cb .r.verdict-r { grid-template-columns: minmax(0,1fr) auto; }
  body.cb .r.verdict-r .you { grid-column: 1 / -1; margin-top: -8px; }
}

/* 4. Thread */
.thread { border-left: 1px solid var(--hair); display: grid; grid-template-rows: auto minmax(0,1fr) auto; grid-template-columns: minmax(0,1fr); min-width: 0; }
.th-h { padding: 18px 20px; border-bottom: 1px solid var(--hair); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.th-h h3 { margin: 0; font: 500 15px var(--f-body); }
.th-h small { display: block; color: var(--muted); font-size: 12px; font-weight: 400; max-width: 30ch; line-height: 1.4; }
.stack { display: flex; }
.stack svg { width: 26px; height: 26px; border-radius: 9px; background: var(--sunk); border: 2px solid var(--win); margin-left: -7px; }
.msgs { overflow-y: auto; padding: 18px 20px 8px; display: flex; flex-direction: column; gap: 16px; }
.day { align-self: center; font-size: 11.5px; color: var(--muted); }
.m { display: flex; flex-direction: column; gap: 6px; max-width: 92%; }
.m-h { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 500; }
.m-h svg { width: 24px; height: 24px; border-radius: 8px; background: var(--sunk); }
.m-h time { font-weight: 400; color: var(--muted); font-size: 11.5px; }
.bubble { background: var(--sunk); border-radius: 4px 16px 16px 16px; padding: 10px 13px; font-size: 13.5px; line-height: 1.45; margin-left: 32px; }
.mine { align-self: flex-end; align-items: flex-end; }
.mine .m-h { flex-direction: row-reverse; }
.mine .m-h .me-s { width: 24px; height: 24px; border-radius: 50%; background: var(--signal); color: #fff; display: grid; place-items: center; font: 500 11px var(--f-display); }
.mine .plain { font-size: 13.5px; text-align: right; margin-right: 32px; }
.reading { font: 400 11.5px var(--f-mono); color: var(--ink-2); display: block; margin-top: 6px; font-variant-numeric: tabular-nums; }
.jobcard { margin-left: 32px; border-radius: 16px; overflow: hidden; border: 1px solid var(--hair-2); }
.jobcard .jc-top { padding: 10px 13px; display: flex; gap: 8px; align-items: center; font: 400 11.5px var(--f-mono); color: var(--ink-2); background: var(--win); }
.jobcard .jc-top .ok { color: var(--good); }
.jobcard .jc-bot { background: var(--ink); color: var(--on-ink); padding: 11px 13px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.jobcard .jc-bot b { font-weight: 500; font-size: 13px; display: block; }
.jobcard .jc-bot small { font-size: 11.5px; opacity: .65; }
.rate { display: flex; gap: 6px; }
.rate button { width: 32px; height: 32px; border-radius: 10px; border: 1px solid color-mix(in srgb, var(--on-ink) 25%, transparent); background: transparent; color: var(--on-ink); display: grid; place-items: center; }
.rate button[aria-pressed="true"] { background: var(--signal); border-color: var(--signal); color: #fff; }
.sys { align-self: center; display: inline-flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.sys .badge { font-size: 9.5px; }
.verdict { margin-left: 32px; border: 1px solid var(--hair-2); border-radius: 16px; padding: 12px 13px; display: flex; flex-direction: column; gap: 10px; }
.verdict p { margin: 0; font-size: 13px; color: var(--ink-2); }
.verdict p b { color: var(--ink); font-weight: 500; }
.acts { display: flex; flex-wrap: wrap; gap: 6px; }
.btn { border: 1px solid var(--hair-2); background: transparent; border-radius: 999px; padding: 7px 13px; font-size: 12.5px; font-weight: 500; }
.btn.dark { background: var(--ink); border-color: var(--ink); color: var(--on-ink); }
.typing { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); padding-left: 2px; }
.typing svg { width: 20px; height: 20px; border-radius: 7px; background: var(--sunk); }
.dots { display: inline-flex; gap: 3px; }
.dots i { width: 4px; height: 4px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.dots i:nth-child(2){animation-delay:.2s}.dots i:nth-child(3){animation-delay:.4s}

.composer { padding: 12px 16px 16px; position: relative; }
.box { border: 1px solid var(--hair-2); border-radius: 18px; padding: 6px 6px 6px 8px; display: flex; align-items: center; gap: 6px; background: var(--win); box-shadow: var(--shadow-pop); }
.plus { width: 34px; height: 34px; border-radius: 12px; border: 0; background: none; color: var(--ink-2); display: grid; place-items: center; flex: none; }
.mention { flex: none; font-size: 12.5px; padding: 3px 8px; border-radius: 8px; background: var(--signal-soft); color: var(--signal); font-weight: 500; }
#ask { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; font-size: 14px; padding: 8px 2px; }
#ask::placeholder { color: var(--muted); }
.send { width: 36px; height: 36px; border-radius: 12px; border: 0; background: var(--ink); color: var(--on-ink); display: grid; place-items: center; flex: none; }
.pop { position: absolute; left: 16px; bottom: calc(100% - 6px); width: 250px; background: var(--win); border: 1px solid var(--hair); border-radius: 16px; box-shadow: var(--shadow-pop); padding: 6px; display: flex; flex-direction: column; z-index: 5; }
.pop button { display: flex; align-items: center; gap: 10px; border: 0; background: none; border-radius: 10px; padding: 7px 8px; text-align: left; }
.pop button:hover, .pop button:focus-visible { background: var(--sunk); }
.pop svg { width: 28px; height: 28px; border-radius: 9px; background: var(--sunk); flex: none; }
.pop small { display: block; color: var(--muted); font-size: 11.5px; }

@keyframes pulse { 50% { opacity: .3; } }
@keyframes wave { 0%,100% { transform: scaleY(.35); } 50% { transform: scaleY(1); } }
@keyframes breathe { 0%,100% { transform: scale(1); } 50% { transform: scale(.55); } }
@keyframes blink { 0%,100% { opacity: .25; } 40% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  .blip, .live .tagl i, .wave span, .working #big circle.t, .dots i { animation: none !important; }
}

/* Laptop: 900px to 1279px. The crew list hides; agents are switched with the stage arrows,
   and the Crew pill carries a signal dot while Waiting on you has items. Chat narrows to 360px. */
@media (min-width: 900px) and (max-width: 1279px) {
  .app { grid-template-columns: 76px minmax(0, 1fr) 360px; }
  .list { display: none; }
  body.cb.has-waiting .pill[data-view="crew"]::after {
    content: ""; position: absolute; top: 1px; right: 1px;
    width: 9px; height: 9px; border-radius: 50%;
    background: var(--signal); border: 2px solid var(--win);
  }
}

/* Phone: under 900px. One column, top to bottom; the page scrolls, columns don't. */
@media (max-width: 899px) {
  body.cb .shell { padding: 16px; place-items: start stretch; }
  body.cb .app { width: 100%; height: auto; grid-template-columns: minmax(0,1fr); grid-template-rows: none; border-radius: 24px; overflow: visible; }
  body.cb .rail { flex-direction: row; justify-content: center; border-right: 0; border-bottom: 1px solid var(--hair); padding: 12px; gap: 8px; }
  body.cb .rail .logo { margin: 0 auto 0 4px; }
  body.cb .rail .spacer, body.cb .rail .pill-l { display: none; }
  body.cb .list-h { flex-direction: column; }
  body.cb .rail .pill.b2 { display: none; }
  body.cb .list { border-right: 0; border-bottom: 1px solid var(--hair); overflow: visible; }
  body.cb .list .group.crew { flex-direction: row; overflow-x: auto; scrollbar-width: none; padding-bottom: 10px; }
  body.cb .list .group.crew::-webkit-scrollbar { display: none; }
  body.cb .list .group.crew .row { width: auto; flex: none; grid-template-columns: 36px auto; padding-right: 14px; }
  body.cb .list .group.crew .row .side, body.cb .list .group.crew .row small { display: none; }
  body.cb .list .group.crew .row .face { width: 36px; height: 36px; }
  body.cb .list .divider, body.cb .list-foot { display: none; }
  body.cb .figure { padding: 0 12px; grid-template-columns: 40px minmax(0,1fr) 40px; }
  body.cb #big { width: min(240px, 100%); height: auto; }
  body.cb .figure { overflow: visible; grid-template-rows: auto; }
  body.cb .card { margin: 0 14px 14px; padding: 18px; grid-template-columns: minmax(0,1fr); }
  body.cb .score { text-align: left; }
  body.cb .who h2, body.cb .score b { font-size: 38px; }
  body.cb .thread { border-left: 0; border-top: 1px solid var(--hair); }
  body.cb .msgs { overflow: visible; }
  body.cb .stage-top { padding: 14px 14px 0; flex-wrap: wrap; }
  body.cb .live { max-width: 100%; }
}
