/* The viewer: the camera fills the screen. While the robot's code is in view, a compact tag hangs
   above it on a tether; when the code leaves the view, the full record docks at the bottom. */

.viewer {
  --viewer-bg: #1c2a36;
  --viewer-ink: #e3eaf0;
  --viewer-muted: #b9c6d0;
  --veil: rgba(28, 42, 54, 0.84);
  position: relative;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--viewer-bg);
  color: var(--viewer-ink);
}

.viewer-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.viewer[data-camera="off"] .viewer-video {
  visibility: hidden;
}

/* --- aiming guide, shown while the camera looks for a code ------------------------------- */

.reticle {
  position: absolute;
  top: 42%;
  left: 50%;
  width: 13em;
  height: 13em;
  transform: translate(-50%, -50%);
  pointer-events: none;
  display: none;
}

.viewer[data-camera="on"]:not([data-tracking]) .reticle {
  display: block;
}

.viewer:has(.tag.docked:not([hidden])) .reticle {
  display: none !important;
}

.reticle span {
  position: absolute;
  width: 2.2em;
  height: 2.2em;
  border: 0 solid var(--mark);
  filter: drop-shadow(0 0 1px rgba(0, 0, 0, 0.6));
}

.reticle span:nth-child(1) { top: 0; left: 0; border-top-width: 4px; border-left-width: 4px; border-top-left-radius: 0.5em; }
.reticle span:nth-child(2) { top: 0; right: 0; border-top-width: 4px; border-right-width: 4px; border-top-right-radius: 0.5em; }
.reticle span:nth-child(3) { bottom: 0; right: 0; border-bottom-width: 4px; border-right-width: 4px; border-bottom-right-radius: 0.5em; }
.reticle span:nth-child(4) { bottom: 0; left: 0; border-bottom-width: 4px; border-left-width: 4px; border-bottom-left-radius: 0.5em; }

/* --- marks over the camera image --------------------------------------------------------- */

.viewer-marks {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  filter: drop-shadow(0 0 1px rgba(0, 0, 0, 0.7));
  display: none;
}

.viewer[data-tracking] .viewer-marks {
  display: block;
}

.code-outline {
  fill: rgba(240, 180, 41, 0.14);
  stroke: var(--mark);
  stroke-width: 3px;
  stroke-linejoin: round;
}

.tether {
  stroke: var(--mark);
  stroke-width: 2px;
}

.viewer[data-tracking="unknown"] .code-outline,
.viewer[data-tracking="unknown"] .tether {
  stroke: var(--mark-unknown);
}

/* --- bar, intro, hint -------------------------------------------------------------------- */

.viewer-bar {
  position: absolute;
  inset: 0 0 auto 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1em;
  padding: max(0.6em, env(safe-area-inset-top)) 1em 0.6em;
  background: var(--veil);
  z-index: 2;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5em;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.brand-mark {
  width: 1.1em;
  height: 1.25em;
  background: var(--honey);
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
}

.bar-button {
  padding: 0.4em 0.85em;
  border: 1px solid rgba(227, 234, 240, 0.5);
  border-radius: var(--radius);
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 0.9em;
  cursor: pointer;
}

.intro {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  gap: 1em;
  max-width: 28em;
  margin: 0 auto;
  padding: 5em 1.5em 2em;
  overflow-y: auto;
}

.intro h1 {
  font-size: 2em;
  font-weight: 700;
  line-height: 1.08;
  letter-spacing: -0.01em;
}

.intro-text {
  color: var(--viewer-muted);
}

.intro-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.45em;
  padding: 0.4em 0 0;
}

.intro-note {
  color: var(--viewer-muted);
  font-size: 0.85em;
}

.intro-error {
  padding: 0.6em 0.8em;
  border-left: 3px solid #f07167;
  background: rgba(240, 113, 103, 0.12);
}

.intro-small a {
  color: var(--honey);
}

/* with a robot's card on screen, the intro keeps only its heading and button */
.viewer:has(.tag:not([hidden])) .intro {
  justify-content: flex-start;
}

.viewer:has(.tag:not([hidden])) .intro-text,
.viewer:has(.tag:not([hidden])) .intro-note,
.viewer:has(.tag:not([hidden])) .intro-small {
  display: none;
}

.hint {
  position: absolute;
  inset: calc(max(0.6em, env(safe-area-inset-top)) + 3.2em) 1em auto 1em;
  padding: 0.55em 0.9em;
  border-radius: var(--radius);
  background: var(--veil);
  text-align: center;
  font-size: 0.95em;
  z-index: 2;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* --- the tag card ------------------------------------------------------------------------ */

.tag {
  --x: 0px;
  --y: 0px;
  --tilt: 0rad;
  --scale: 1;
  position: absolute;
  left: 0;
  top: 0;
  width: 18em;
  max-width: calc(100vw - 1.5em);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  transform-origin: 0 0;
  transform: translate(var(--x), var(--y)) rotate(var(--tilt)) scale(var(--scale)) translate(-50%, -100%);
  z-index: 3;
}

/* the eyelet the tether ties to: on the edge that faces the code */
.tag::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -0.55em;
  width: 1em;
  height: 1.1em;
  transform: translateX(-50%);
  background: var(--honey);
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
}

.tag.below::after {
  top: -0.55em;
  bottom: auto;
}

/* pinned to the code: the essentials only; docked: the full record */
.tag:not(.docked) .tag-detail {
  display: none;
}

.tag:not(.docked) .tag-name {
  font-size: 1.2em;
}

.tag.docked {
  top: auto;
  bottom: max(1em, env(safe-area-inset-bottom));
  left: 50%;
  width: 21em;
  max-height: calc(100% - 9.5em); /* below the bar and the intro's button or the hint; scrolls on short screens */
  overflow-y: auto;
  transform: translateX(-50%);
}

.tag.docked::after {
  display: none;
}

/* camera off with a robot's card (opened from a link, or after "Stop camera"): the card follows the
   intro in the page flow, and the page scrolls */
.viewer[data-camera="off"]:has(.tag:not([hidden])) {
  overflow-y: auto;
  padding: 0 0 1.5em;
}

.viewer[data-camera="off"]:has(.tag:not([hidden])) .intro {
  position: relative;
  inset: auto;
  padding: 5em 1.5em 1.25em;
}

.viewer[data-camera="off"] .tag.docked {
  position: relative;
  inset: auto;
  max-height: none;
  margin: 0 auto;
  transform: none;
}

.tag[data-state="unknown"] .tag-band {
  background: var(--mark-unknown);
}

.tag-band {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1em;
  padding: 0.45em 0.9em;
  border-radius: var(--radius) var(--radius) 0 0;
  background: var(--honey);
  color: var(--honey-ink);
  font-size: 0.85em;
}

.tag-band-title {
  font-weight: 700;
}

.tag-status {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  font-weight: 600;
}

.tag-status::before {
  content: "";
  width: 0.6em;
  height: 0.6em;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.45;
}

.tag-status[data-status="ok"]::before {
  opacity: 1;
  background: #0f5c4c;
}

.tag-status[data-status="stale"]::before,
.tag-status[data-status="error"]::before,
.tag-status[data-status="unknown"]::before {
  opacity: 1;
  background: #8f1c13;
}

.tag-body {
  display: flex;
  flex-direction: column;
  gap: 0.65em;
  padding: 0.75em 0.9em 0.9em;
}

.tag-heading {
  display: flex;
  flex-direction: column;
  gap: 0.2em;
}

.tag-name {
  font-size: 1.35em;
  font-weight: 700;
  line-height: 1.1;
}

.tag-identity {
  display: flex;
  align-items: center;
  gap: 0.35em;
  color: var(--ink-muted);
  font-size: 0.9em;
  font-weight: 600;
}

.tag-identity[data-tone="ok"] {
  color: var(--ok);
}

.tag-identity[data-tone="ok"]::before {
  content: "✓";
  font-weight: 700;
}

.tag-identity[data-tone="warn"] {
  color: var(--warn);
}

.tag-did {
  color: var(--ink-muted);
  font-size: 0.8em;
  overflow-wrap: anywhere;
}

.tag-message {
  font-size: 0.95em;
}

.tag-record {
  display: flex;
  flex-direction: column;
  gap: 0.55em;
  padding: 0.65em 0 0;
  border-top: 1px solid var(--line);
}

.tag-count {
  display: flex;
  align-items: baseline;
  gap: 0.35em;
  font-weight: 600;
}

.tag-count-number {
  font-size: 1.9em;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--honey-deep);
}

/* records by type: name and count on one line, the latest one's age under the name */
.tag-types {
  display: flex;
  flex-direction: column;
  gap: 0.35em;
  padding: 0;
  margin: 0;
  list-style: none;
  font-size: 0.9em;
}

.tag-types li {
  display: grid;
  grid-template-columns: 1fr auto;
  column-gap: 0.75em;
  align-items: baseline;
}

.type-name {
  font-weight: 600;
}

.type-count {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.type-last {
  grid-column: 1 / -1;
  color: var(--ink-muted);
  font-size: 0.85em;
}

.tag-latest {
  display: flex;
  flex-direction: column;
  gap: 0.15em;
  padding: 0.55em 0.7em;
  border-left: 3px solid var(--honey);
  border-radius: 0 var(--radius) var(--radius) 0;
  background: var(--surface-sunk);
  font-size: 0.9em;
}

.tag-latest h3 {
  font-size: 0.85em;
  font-weight: 600;
  color: var(--ink-muted);
}

.tag-latest-what {
  font-weight: 700;
}

.tag-link {
  color: var(--focus);
  font-weight: 600;
  padding: 0.25em 0 0;
}

.tag-wallet {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75em;
  font-size: 0.9em;
}

.tag-wallet dt {
  color: var(--ink-muted);
  font-size: 0.85em;
}

.tag-wallet dd {
  font-weight: 600;
}

.tag-foot {
  color: var(--ink-muted);
  font-size: 0.75em;
}

@media (prefers-reduced-motion: no-preference) {
  .tag-status[data-status="ok"]::before {
    animation: live 2.4s ease-in-out infinite;
  }

  .viewer[data-camera="on"]:not([data-tracking]) .reticle {
    animation: aim 2.4s ease-in-out infinite;
  }
}

@keyframes live {
  50% {
    opacity: 0.35;
  }
}

@keyframes aim {
  50% {
    opacity: 0.55;
  }
}
