/*
 * lispm-remote: the page at lispm.ai/remote.
 *
 * Copyright (C) 2026  Ryan.K
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */

:root {
  --paper: #f4f1ea;
  --card: #fffdf8;
  --ink: #1d1c1a;
  --dim: #6d6a63;
  --line: #ddd7cb;
  --accent: #2f5bd3;
  --ok: #2e8540;
  --busy: #b7791f;
  --bad: #c0392b;
  --wait: #fff3d6;
  --radius: 14px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #16161a;
    --card: #222228;
    --ink: #ecebe6;
    --dim: #9d9a92;
    --line: #36363e;
    --accent: #7f9cff;
    --ok: #5cc277;
    --busy: #e2a84b;
    --bad: #ff7a6b;
    --wait: #3a311d;
  }
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom)
    env(safe-area-inset-left);
}

.top,
main,
footer {
  max-width: 40rem;
  margin: 0 auto;
  padding: 0 1rem;
}

.top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding-top: 1rem;
  padding-bottom: 0.5rem;
}

h1 {
  font-size: 1.15rem;
  margin: 0;
  letter-spacing: 0.01em;
}

h2 {
  font-size: 1.05rem;
  margin: 0;
}

.status {
  margin: 0;
  font-size: 0.9rem;
  color: var(--dim);
  white-space: nowrap;
}

.status::before {
  content: "";
  display: inline-block;
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  margin-right: 0.4rem;
  background: var(--busy);
}

.status.ok::before {
  background: var(--ok);
}

.status.bad::before {
  background: var(--bad);
}

.status.busy::before {
  animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
  50% {
    opacity: 0.3;
  }
}

.notice {
  margin: 0.25rem 0 0.75rem;
  min-height: 0;
  font-size: 0.95rem;
}

.notice:empty {
  display: none;
}

.notice.info {
  color: var(--ok);
}

.notice.error {
  color: var(--bad);
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 0.9rem;
}

/* Pairing and reconnecting, as steps */

.stepper-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
}

.stepper-head .count {
  font-size: 0.85rem;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
}

.overall {
  height: 4px;
  margin: 0.7rem 0 1rem;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}

.overall span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--ok));
  transition: width 0.6s ease;
}

.steps {
  list-style: none;
  margin: 0;
  padding: 0;
}

.step {
  position: relative;
  display: flex;
  gap: 0.85rem;
  padding-bottom: 1.1rem;
}

/* The line from one step's mark to the next. */
.step:not(:last-child)::before {
  content: "";
  position: absolute;
  left: calc(1rem - 1px);
  top: 2.2rem;
  bottom: 0.2rem;
  width: 2px;
  border-radius: 1px;
  background: var(--line);
  transition: background 0.4s ease;
}

.step[data-state="done"]:not(:last-child)::before,
.step[data-state="skipped"]:not(:last-child)::before {
  background: var(--ok);
}

.mark {
  position: relative;
  flex: none;
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  border: 2px solid var(--line);
  color: var(--dim);
  font-weight: 600;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
  background: var(--card);
  transition: background 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

.mark .number,
.mark .tick {
  grid-area: 1 / 1;
}

.mark .tick {
  width: 1.1rem;
  height: 1.1rem;
  fill: none;
  stroke: #fff;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 24;
  stroke-dashoffset: 24;
  opacity: 0;
}

.step[data-state="active"] .mark {
  border-color: var(--accent);
  color: var(--accent);
  animation: pulse-ring 1.6s ease-out infinite;
}

.step[data-state="done"] .mark {
  border-color: var(--ok);
  background: var(--ok);
  animation: pop 0.35s ease-out;
}

.step[data-state="done"] .mark .number {
  opacity: 0;
}

.step[data-state="done"] .mark .tick {
  opacity: 1;
  animation: draw 0.45s 0.1s ease-out forwards;
}

.step[data-state="skipped"] .mark {
  border-style: dashed;
  border-color: var(--ok);
  color: var(--ok);
}

.step[data-state="failed"] .mark {
  border-color: var(--bad);
  color: var(--bad);
}

/* Paired, or back: a ring goes out from the last mark. */
.step[data-step="connected"][data-state="done"] .mark::after {
  content: "";
  position: absolute;
  inset: -2px;
  border-radius: 50%;
  border: 2px solid var(--ok);
  animation: burst 0.9s 0.2s ease-out both;
}

.step .body {
  flex: 1;
  min-width: 0;
  padding-top: 0.2rem;
}

.step .title {
  margin: 0;
  font-weight: 600;
}

.step[data-state="pending"] .title {
  color: var(--dim);
  font-weight: 500;
}

.step .detail {
  margin: 0.1rem 0 0;
  color: var(--dim);
  font-size: 0.88rem;
  overflow-wrap: anywhere;
}

.step[data-state="failed"] .detail {
  color: var(--bad);
}

.bar {
  position: relative;
  height: 6px;
  margin-top: 0.55rem;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}

.bar span {
  position: absolute;
  inset: 0 auto 0 0;
  border-radius: inherit;
  background: var(--accent);
}

.bar.busy span {
  width: 40%;
  animation: sweep 1.3s ease-in-out infinite;
}

.bar.countdown span {
  transition: width 1s linear, background 0.4s ease;
}

.bar.countdown.half span {
  background: var(--busy);
}

.bar.countdown.low span {
  background: var(--bad);
}

.extra:empty {
  display: none;
}

.extra > button {
  margin-top: 0.75rem;
}

.viewfinder {
  position: relative;
  width: 100%;
  max-width: 22rem;
  aspect-ratio: 1;
  margin-top: 0.75rem;
  border-radius: calc(var(--radius) - 2px);
  overflow: hidden;
  background: #000;
}

.viewfinder video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.viewfinder .corner {
  position: absolute;
  width: 18%;
  height: 18%;
  border: 3px solid #fff;
  opacity: 0.9;
}

.viewfinder .tl {
  top: 8%;
  left: 8%;
  border-right: none;
  border-bottom: none;
  border-top-left-radius: 10px;
}

.viewfinder .tr {
  top: 8%;
  right: 8%;
  border-left: none;
  border-bottom: none;
  border-top-right-radius: 10px;
}

.viewfinder .bl {
  bottom: 8%;
  left: 8%;
  border-right: none;
  border-top: none;
  border-bottom-left-radius: 10px;
}

.viewfinder .br {
  bottom: 8%;
  right: 8%;
  border-left: none;
  border-top: none;
  border-bottom-right-radius: 10px;
}

.viewfinder .laser {
  position: absolute;
  left: 10%;
  right: 10%;
  top: 10%;
  height: 2px;
  border-radius: 1px;
  background: var(--accent);
  box-shadow: 0 0 12px 2px var(--accent);
  animation: scan 2.2s ease-in-out infinite alternate;
}

.fingerprint {
  margin: 0.7rem 0 0;
  padding: 0.6rem 0.5rem;
  border-radius: 12px;
  background: var(--paper);
  font: 600 2.3rem/1.15 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  letter-spacing: 0.09em;
  text-align: center;
  animation: rise 0.4s ease-out;
}

@keyframes pulse-ring {
  0% {
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 45%, transparent);
  }
  100% {
    box-shadow: 0 0 0 10px transparent;
  }
}

@keyframes pop {
  0% {
    transform: scale(0.8);
  }
  60% {
    transform: scale(1.12);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes draw {
  to {
    stroke-dashoffset: 0;
  }
}

@keyframes burst {
  0% {
    transform: scale(1);
    opacity: 0.9;
  }
  100% {
    transform: scale(2.4);
    opacity: 0;
  }
}

@keyframes sweep {
  0% {
    left: -40%;
  }
  100% {
    left: 100%;
  }
}

@keyframes scan {
  0% {
    top: 10%;
  }
  100% {
    top: 90%;
  }
}

@keyframes rise {
  0% {
    opacity: 0;
    transform: translateY(6px);
  }
  100% {
    opacity: 1;
    transform: none;
  }
}

/* Asked for less motion: every state shows, nothing moves. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }

  .step[data-state="done"] .mark .tick {
    stroke-dashoffset: 0;
  }

  .bar.busy span {
    width: 100%;
    opacity: 0.45;
  }

  .viewfinder .laser {
    top: 50%;
    opacity: 0.6;
  }
}

.stale {
  opacity: 0.6;
}

/* The agents */

#agents {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

button.agent {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.2rem;
  width: 100%;
  text-align: left;
  font-weight: 400;
  padding: 0.9rem 1rem;
  background: var(--card);
  border-radius: var(--radius);
}

.agent .row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.agent strong {
  overflow-wrap: anywhere;
}

.agent .asked {
  color: var(--busy);
  font-size: 0.9rem;
}

.project,
.activity,
.aside {
  margin: 0;
  color: var(--dim);
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

.aside {
  text-align: center;
  margin: 0.5rem 0;
}

.badge {
  flex: none;
  font-size: 0.8rem;
  padding: 0.1rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--dim);
}

.badge.requesting,
.badge.acting {
  color: var(--accent);
  border-color: var(--accent);
}

.badge.waiting {
  color: var(--busy);
  border-color: var(--busy);
}

/* A chat with one agent */

.chat-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}

.chat-head .who {
  flex: 1;
  min-width: 0;
}

.chat-head .activity {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

button.back {
  min-height: 2.5rem;
  padding: 0 0.8rem;
  font-size: 1.4rem;
  line-height: 1;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding: 0.9rem 0;
}

.message {
  display: flex;
  flex-direction: column;
  max-width: 86%;
}

.message.mine {
  align-self: flex-end;
  align-items: flex-end;
}

.message.theirs {
  align-self: flex-start;
}

.message .from {
  font-size: 0.75rem;
  color: var(--dim);
  margin: 0 0.4rem 0.15rem;
}

.bubble {
  padding: 0.55rem 0.85rem;
  border-radius: 18px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.mine .bubble {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 5px;
}

.mine.sending .bubble {
  opacity: 0.55;
}

.theirs .bubble {
  background: var(--card);
  border: 1px solid var(--line);
  border-bottom-left-radius: 5px;
  white-space: normal;
}

.theirs .bubble p {
  margin: 0;
  white-space: pre-wrap;
}

.theirs .bubble p + p,
.theirs .bubble p + pre,
.theirs .bubble pre + p {
  margin-top: 0.6rem;
}

.bubble code,
.bubble pre,
.call .input,
.call pre,
.thought p {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.85rem;
}

.bubble code {
  padding: 0.05rem 0.3rem;
  border-radius: 5px;
  background: var(--paper);
}

.bubble pre,
.call pre {
  margin: 0;
  padding: 0.6rem;
  border-radius: 8px;
  background: var(--paper);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.call,
.thought {
  align-self: stretch;
  font-size: 0.9rem;
  color: var(--dim);
}

.call summary,
.thought summary {
  display: flex;
  gap: 0.5rem;
  align-items: baseline;
  cursor: pointer;
  list-style: none;
}

.call summary::-webkit-details-marker,
.thought summary::-webkit-details-marker {
  display: none;
}

.call .tool {
  color: var(--ink);
  font-weight: 500;
}

.call .input {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.call .state {
  flex: none;
  font-size: 0.8rem;
}

.call .state.done {
  color: var(--ok);
}

.call .state.failed,
.call .state.denied,
.call.failed .state {
  color: var(--bad);
}

.call .state.waiting {
  color: var(--busy);
}

.call pre {
  margin-top: 0.4rem;
  max-height: 14rem;
  overflow: auto;
}

.thought p {
  margin: 0.4rem 0 0;
  white-space: pre-wrap;
}

.composer {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.6rem 0 calc(0.6rem + env(safe-area-inset-bottom));
  background: var(--paper);
}

.composer textarea {
  flex: 1;
  min-width: 0;
  min-height: 2.75rem;
  max-height: 10rem;
  resize: none;
  font: inherit;
  padding: 0.6rem 0.8rem;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
}

.composer button {
  border-radius: 20px;
}

.approval {
  margin: 0 0 0.6rem;
  padding: 0.75rem;
  border-radius: var(--radius);
  background: var(--wait);
}

.approval .asks {
  margin: 0;
}

.approval pre {
  margin: 0.5rem 0 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font: 0.85rem/1.4 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  max-height: 12rem;
  overflow: auto;
}

.decisions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.decisions button {
  flex: 1;
}

button {
  font: inherit;
  font-weight: 500;
  min-height: 2.75rem;
  padding: 0.5rem 1rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

button.danger {
  color: var(--bad);
  border-color: var(--bad);
  background: transparent;
}

button.quiet,
button.link {
  background: transparent;
}

button.link {
  border: none;
  padding: 0;
  min-height: 0;
  color: var(--accent);
  font-weight: 400;
  text-align: left;
}

button:active {
  transform: translateY(1px);
}

[hidden] {
  display: none !important;
}

footer {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding-top: 0.5rem;
  padding-bottom: 2rem;
  font-size: 0.8rem;
  color: var(--dim);
}

footer .did {
  overflow-wrap: anywhere;
}

/* LispM's windows: the display's view over the whole page. */
.windows {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  padding-top: env(safe-area-inset-top);
}

.windows[hidden] {
  display: none;
}

.windows-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
}

.windows-head h2 {
  margin: 0;
  font-size: 1rem;
}

.windows-view {
  flex: 1;
  min-height: 0;
  padding-bottom: env(safe-area-inset-bottom);
}
