:root {
  --bg: #0d1117;
  --card: #161b22;
  --card-2: #1f2630;
  --line: #2a323d;
  --fg: #e6edf3;
  --fg-2: #9aa7b4;
  --accent: #f5b942;
  --ok: #3fb950;
  --warn: #f0a63a;
  --bad: #f85149;
  --idle: #6e7b88;
  --radius: 14px;
  color-scheme: dark;
}
* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
body {
  padding: env(safe-area-inset-top) 0 calc(72px + env(safe-area-inset-bottom));
}
main {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 16px;
}
h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg-2);
  margin: 22px 0 8px;
}
a {
  color: inherit;
}
code {
  font-size: 12px;
}
.muted {
  color: var(--fg-2);
}
.small {
  font-size: 12px;
}

/* header */
.top {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand {
  font-weight: 700;
  font-size: 17px;
}
.live {
  display: flex;
  gap: 6px;
  align-items: center;
  font-size: 12px;
  color: var(--fg-2);
}
.live .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--idle);
}
.live.on .dot {
  background: var(--ok);
  animation: pulse 2s infinite;
}
.live.off .dot {
  background: var(--bad);
}
@keyframes pulse {
  50% {
    opacity: 0.35;
  }
}
.offline {
  margin: 10px 16px 0;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--bad) 18%, var(--card));
  border: 1px solid var(--bad);
  font-size: 13px;
}

/* cards */
.card,
.tile,
.agent,
.row {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.card {
  padding: 14px;
  margin-top: 12px;
}
.label {
  font-size: 12px;
  color: var(--fg-2);
}
.big {
  font-size: 34px;
  font-weight: 800;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.hero-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 12px;
}
.countdown {
  text-align: right;
}
.countdown .big {
  color: var(--accent);
}
.bar {
  height: 12px;
  border-radius: 99px;
  background: var(--card-2);
  overflow: hidden;
  margin: 10px 0;
}
.bar.small {
  height: 6px;
  margin: 4px 0 10px;
}
.bar .fill {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), #ffd98a);
  transition: width 0.8s ease;
}
.bar.warn .fill {
  background: var(--warn);
}
.sub {
  display: grid;
  grid-template-columns: 76px 1fr 44px;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--fg-2);
}
.sub .bar {
  margin: 0;
}
.sub b {
  text-align: right;
  color: var(--fg);
}

/* tiles */
.tiles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}
.tile {
  padding: 12px;
}
.tile .value {
  font-size: 22px;
  font-weight: 700;
  margin: 2px 0;
  font-variant-numeric: tabular-nums;
}
.tile .hint {
  font-size: 11px;
  color: var(--fg-2);
}
.tile.ok .value,
.ok-t {
  color: var(--ok);
}
.tile.warn .value {
  color: var(--warn);
}
.tile.bad .value,
.bad-t {
  color: var(--bad);
}
.tile.muted .value {
  color: var(--idle);
}

/* agents */
.agents {
  display: grid;
  gap: 10px;
}
.agent {
  padding: 12px;
  border-left: 4px solid var(--idle);
}
.agent.ok {
  border-left-color: var(--ok);
}
.agent.warn {
  border-left-color: var(--warn);
}
.agent.bad {
  border-left-color: var(--bad);
}
.agent-head {
  display: flex;
  align-items: center;
  gap: 10px;
}
.agent-head > div {
  flex: 1;
  min-width: 0;
}
.emoji {
  font-size: 26px;
}
.doing {
  margin: 8px 0 6px;
  font-size: 14px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.ticket {
  font-weight: 700;
  color: var(--accent);
  margin-right: 6px;
}
.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  font-size: 11px;
  color: var(--fg-2);
}
.pill {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 99px;
  background: var(--card-2);
  color: var(--fg-2);
  white-space: nowrap;
}
.pill.ok {
  background: color-mix(in srgb, var(--ok) 20%, transparent);
  color: var(--ok);
}
.pill.warn,
.pill.zone-frozen {
  background: color-mix(in srgb, var(--warn) 20%, transparent);
  color: var(--warn);
}
.pill.bad {
  background: color-mix(in srgb, var(--bad) 20%, transparent);
  color: var(--bad);
}
.pill.zone-core {
  background: color-mix(in srgb, #58a6ff 20%, transparent);
  color: #79b8ff;
}
.pill.zone-free {
  background: color-mix(in srgb, var(--ok) 15%, transparent);
  color: var(--ok);
}

/* lists */
.list {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
}
html,
body {
  overflow-x: hidden;
}
.row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  text-decoration: none;
  font-size: 14px;
}
.row.done {
  opacity: 0.6;
}
.grow {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.num {
  font-variant-numeric: tabular-nums;
  color: var(--fg-2);
  min-width: 28px;
}
.kv {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0;
  font-size: 14px;
}
.kv span {
  color: var(--fg-2);
}
.kv b {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* chart */
.bars {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 120px;
  border-top: 1px dashed var(--line);
}
.col {
  flex: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  font-size: 9px;
  color: var(--fg-2);
}
.colfill {
  width: 100%;
  min-height: 2px;
  border-radius: 4px 4px 0 0;
  background: var(--accent);
}
.colfill.bad {
  background: var(--bad);
}

/* tab bar */
.tabs {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.tabs button {
  appearance: none;
  border: 0;
  background: none;
  color: var(--fg-2);
  font: inherit;
  font-size: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 4px 0;
  min-height: 44px;
}
.tabs button span {
  font-size: 20px;
}
.tabs button.active {
  color: var(--accent);
}
.logout {
  display: block;
  text-align: center;
  margin: 28px 0;
  color: var(--fg-2);
  font-size: 13px;
}

/* login */
.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}
.login form {
  width: 100%;
  max-width: 340px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 24px;
}
.login h1 {
  margin: 0 0 4px;
  font-size: 22px;
}
.login input {
  width: 100%;
  font: inherit;
  font-size: 16px;
  margin: 16px 0 12px;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--fg);
}
.login button {
  width: 100%;
  font: inherit;
  font-weight: 700;
  padding: 12px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: #1a1300;
  min-height: 44px;
}
.login .error {
  color: var(--bad);
  font-size: 13px;
}

/* studio scene (office.webp is 1168x880; positions are % of it) */
.studio {
  position: relative;
  aspect-ratio: 1168 / 880;
  margin-top: 12px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  overflow: hidden;
  background: #0b1020;
  container-type: inline-size;
}
.studio .office {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}
.rack {
  position: absolute;
  left: 89.2%;
  top: 23%;
  width: 5.2%;
  height: 31%;
  background: repeating-linear-gradient(0deg, transparent 0 7px, rgba(80, 255, 140, 0.55) 7px 8px);
  mix-blend-mode: screen;
  animation: blink 1.3s steps(2) infinite;
}
.screen {
  position: absolute;
  width: 9.6%;
  height: 7%;
  border-radius: 2px;
  transition: background-color 0.6s;
}
.screen[data-agent='api_architect'] { left: 21.3%; top: 39.8%; }
.screen[data-agent='art_audio'] { left: 45%; top: 39.8%; }
.screen[data-agent='guardian'] { left: 69.9%; top: 39.8%; }
.screen[data-agent='server_dev'] { left: 14%; top: 59.2%; width: 11.5%; height: 8.2%; }
.screen[data-agent='maestro'] { left: 44%; top: 59.2%; width: 11.5%; height: 8.2%; }
.screen[data-agent='ui_builder'] { left: 74.2%; top: 59.2%; width: 11.5%; height: 8.2%; }
.screen.working {
  background: repeating-linear-gradient(180deg, rgba(160, 255, 200, 0.75) 0 2px, transparent 2px 5px) 0 0 / 70% 200% no-repeat, rgba(20, 40, 30, 0.75);
  background-position: 12% 0;
  animation: code 1.6s steps(8) infinite;
}
.screen.idle,
.screen.offline {
  background: rgba(5, 8, 16, 0.55);
}
.screen.blocked {
  background: rgba(240, 166, 58, 0.45);
  animation: blink 1s steps(2) infinite;
}
.screen.error {
  background: rgba(248, 81, 73, 0.55);
  animation: blink 0.7s steps(2) infinite;
}

.bot {
  position: absolute;
  height: 17%;
  transform: translateX(-50%);
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.bot img {
  display: block;
  height: 100%;
  width: auto;
  filter: drop-shadow(0 2px 0 rgba(0, 0, 0, 0.45));
  transform-origin: 50% 100%;
}
.bot[data-agent='api_architect'] { left: 25.7%; bottom: 39%; height: 14%; }
.bot[data-agent='art_audio'] { left: 49.8%; bottom: 39%; height: 14%; }
.bot[data-agent='guardian'] { left: 74.5%; bottom: 39%; height: 14%; }
.bot[data-agent='server_dev'] { left: 19.4%; bottom: 8%; height: 19%; z-index: 1; }
.bot[data-agent='maestro'] { left: 49.8%; bottom: 8%; height: 19%; z-index: 1; }
.bot[data-agent='ui_builder'] { left: 80%; bottom: 8%; height: 19%; z-index: 1; }
.tag {
  position: absolute;
  left: 50%;
  top: 100%;
  transform: translate(-50%, 2px);
  padding: 0 4px;
  border-radius: 3px;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: clamp(8px, 1.9cqw, 12px);
  line-height: 1.5;
  white-space: nowrap;
}
.bubble {
  position: absolute;
  left: 50%;
  bottom: 100%;
  transform: translate(-50%, -2px);
  min-width: 16px;
  padding: 1px 5px;
  border-radius: 6px;
  background: #fff;
  color: #10141c;
  font: 700 clamp(9px, 2.2cqw, 13px) / 1.45 ui-monospace, Menlo, monospace;
  white-space: nowrap;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.4);
}
.bubble:empty {
  display: none;
}
.bubble::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 100%;
  margin-left: -3px;
  border: 3px solid transparent;
  border-top-color: #fff;
}
.bot.working img { animation: type 0.36s steps(2) infinite; }
.bot.working .bubble { background: var(--ok); color: #04210c; }
.bot.working .bubble::after { border-top-color: var(--ok); }
.bot.idle img { animation: breathe 3.2s ease-in-out infinite; }
.bot.idle .bubble { background: none; box-shadow: none; color: #cfe3ff; font-size: 11px; animation: snooze 2.6s ease-in-out infinite; }
.bot.idle .bubble::after { display: none; }
.bot.blocked img { animation: wiggle 1.2s ease-in-out infinite; }
.bot.blocked .bubble { background: var(--warn); color: #2a1700; animation: pop 1s ease-in-out infinite; }
.bot.blocked .bubble::after { border-top-color: var(--warn); }
.bot.error img { animation: shake 0.5s steps(3) infinite; filter: drop-shadow(0 0 4px var(--bad)); }
.bot.error .bubble { background: var(--bad); color: #fff; }
.bot.error .bubble::after { border-top-color: var(--bad); }
.bot.offline img { filter: grayscale(1) brightness(0.6); }

.studio-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

@keyframes blink { 50% { opacity: 0.35; } }
@keyframes code { to { background-position: 12% 100%; } }
@keyframes type { 50% { transform: translateY(-3%) rotate(-1deg); } }
@keyframes breathe { 50% { transform: scaleY(0.975); } }
@keyframes snooze {
  0% { transform: translate(-50%, 0); opacity: 0; }
  30% { opacity: 1; }
  100% { transform: translate(-10%, -70%); opacity: 0; }
}
@keyframes wiggle { 25% { transform: rotate(-4deg); } 75% { transform: rotate(4deg); } }
@keyframes pop { 50% { transform: translate(-50%, -5px) scale(1.12); } }
@keyframes shake { 33% { transform: translateX(-3%); } 66% { transform: translateX(3%); } }

@media (prefers-reduced-motion: reduce) {
  .studio *,
  .studio *::after { animation: none !important; }
}

/* filters and history */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 4px 0 10px;
}
.chips button {
  appearance: none;
  font: inherit;
  font-size: 13px;
  padding: 7px 12px;
  min-height: 36px;
  border-radius: 99px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--fg-2);
}
.chips button.active {
  background: color-mix(in srgb, var(--accent) 18%, var(--card));
  border-color: var(--accent);
  color: var(--accent);
}
.chips.static {
  margin-bottom: 8px;
}
.day {
  margin: 14px 0 6px;
  font-size: 12px;
  color: var(--fg-2);
}
.day::first-letter {
  text-transform: uppercase;
}
.more {
  display: block;
  width: 100%;
  margin-top: 10px;
  min-height: 44px;
  font: inherit;
  border-radius: var(--radius);
  border: 1px dashed var(--line);
  background: none;
  color: var(--fg-2);
}
.colnum {
  font-size: 10px;
  color: var(--fg);
  margin-bottom: 2px;
}
#period-sum {
  margin-top: 0;
}

/* actions */
.crew-state {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--card);
  font-weight: 600;
}
.crew-state.ok { border-color: var(--ok); color: var(--ok); }
.crew-state.paused { border-color: var(--warn); color: var(--warn); }
.crew-state.bad { border-color: var(--bad); color: var(--bad); }
.order textarea {
  width: 100%;
  font: inherit;
  font-size: 16px;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--fg);
  resize: vertical;
}
.order-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
}
.btn {
  appearance: none;
  font: inherit;
  font-weight: 700;
  min-height: 44px;
  padding: 10px 18px;
  border: 0;
  border-radius: 10px;
}
.btn:disabled { opacity: 0.5; }
.btn.primary { background: var(--accent); color: #1a1300; }
.btn.danger, .btn.ok { width: 100%; }
.btn.danger { background: var(--bad); color: #fff; }
.btn.ok { background: var(--ok); color: #04210c; }
.log {
  display: block;
  padding: 10px 12px;
  font-size: 13px;
}
.log .msg {
  margin-top: 6px;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--fg-2);
  max-height: 9em;
  overflow: auto;
}
.studio.paused .office,
.studio.paused .bot img { filter: grayscale(1) brightness(0.55); }
.studio.paused .bot img,
.studio.paused .screen,
.studio.paused .rack,
.studio.paused .bubble { animation: none; }
.studio.paused::after {
  content: 'PAUSE';
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font: 800 clamp(22px, 9cqw, 56px) / 1 ui-monospace, Menlo, monospace;
  letter-spacing: 0.2em;
  color: var(--warn);
  text-shadow: 0 2px 0 #000;
  z-index: 2;
}

/* notifications */
.prefs {
  display: grid;
  gap: 10px;
  margin: 6px 0 14px;
  font-size: 14px;
}
.prefs label {
  display: flex;
  gap: 10px;
  align-items: center;
  min-height: 32px;
}
.prefs input {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
}
.push-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.btn:not(.primary):not(.danger):not(.ok) {
  background: var(--card-2);
  color: var(--fg);
}

/* the hidden attribute must win over any display rule */
[hidden] {
  display: none !important;
}
