:root {
  --ink: #222;
  --muted: #5f6b76;
  --line: #dfe3e8;
  --panel: #f7f8f9;
  --brand: #ed341d;
  --brand-dark: #c72d1c;
  --blue: #005a9c;
  --link: #4183c4;
  --warn: #8a6100;
  --ok: #1f7a4d;
  --radius: 8px;
}

body{
  font-family: Neo Sans, sans-serif;
  padding: 0;
}

.page {
  max-width: 79rem;
  margin: 0 auto;
}

h1 {
  text-decoration: none;
  text-decoration-thickness: 3px;
  text-underline-offset: 6px;
  font-weight: 600;
}

h2{
  color: #222;
}

#usermedia-html-element h3 {
  font-weight: bold;
  color: var(--blue);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin: 0 0 0.6rem;
  font-size: 140%;
}

#usermedia-html-element h4 {
  color: var(--ink);
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0.4rem 0;
}

p {
  margin: 0 0 1rem;
}

#usermedia-html-element a {
  color: var(--link);
  text-decoration: none;
}

#usermedia-html-element a:hover,
#usermedia-html-element a:focus-visible {
  color: var(--blue);
  text-decoration: underline;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.88em;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0.05em 0.3em;
}

.byline {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 1.25rem;
}

.lede {
  max-width: 62ch;
}

/* ---------- layout ---------- */

.card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  margin: 0 0 1.25rem;
  background: #fff;
}

.card--muted {
  background: var(--panel);
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(17rem, 1fr));
  gap: 1.25rem;
  margin: 0 0 1.25rem;
}

.grid-2 > .card {
  margin: 0;
}

/* Nested inside a card: tighter, and the card owns the outer spacing. */
.grid-2--fields {
  gap: 1rem;
  margin-bottom: 0;
}

.card h2:not(:first-child) {
  margin-top: 1.5rem;
}

.card h3 {
  margin-top: 1.4rem;
}

.card h3:first-child {
  margin-top: 0;
}

.stack > * + * {
  margin-top: 1rem;
}

.stack--offset {
  margin-top: 1rem;
}

.stack--offset-sm {
  margin-top: 0.75rem;
}

#stats{
  padding-left: 0 !important;
}

.stats li{
  margin: 0 0 1rem;
  padding-left: 1.25rem;
  list-style: none;
}

#usermedia-html-element ul,
#usermedia-html-element ol {
  margin: 0 0 1rem;
  padding-left: 1.25rem;
  list-style: disc;
}

li + li {
  margin-top: 0.2rem;
}

.hint {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0.35rem 0 0;
  margin-bottom: 20px;
}

.is-hidden {
  display: none !important;
}

/* ---------- form controls ---------- */

.field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  min-width: 0;
}

.field > label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.field > label code {
  text-transform: none;
  letter-spacing: 0;
}

select,
input[type="text"],
textarea {
  width: 100%;
  font: inherit;
  font-size: 0.95rem;
  color: inherit;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
}

textarea {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.8rem;
  line-height: 1.5;
  resize: vertical;
  tab-size: 2;
}

textarea.is-invalid {
  border-color: var(--brand);
  background: rgba(237, 52, 29, 0.04);
}

select:disabled,
input[type="text"]:disabled,
textarea:disabled {
  background: var(--panel);
  color: var(--muted);
}

.checkbox {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  font-size: 0.9rem;
  line-height: 1.4;
}

.checkbox input {
  margin: 0.25rem 0 0;
  flex: none;
}

:where(button, select, input, textarea, a):focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

/* ---------- buttons ---------- */

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 20px;
}

.button {
  flex: 1 1 9rem;
  min-height: 2.75rem;
  padding: 0.5rem 1rem;
  border: 1px solid var(--brand);
  border-radius: 5px;
  background: var(--brand);
  color: #fff;
  font: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 0.4rem;
}

.button:hover:not(:disabled) {
  background: var(--brand-dark);
  border-color: var(--brand-dark);
}

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

.button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.button--secondary {
  background: #fff;
  color: var(--ink);
  border-color: var(--line);
}

.button--secondary:hover:not(:disabled) {
  background: var(--panel);
  border-color: var(--muted);
  color: var(--ink);
}

.button--small {
  flex: 0 0 auto;
  min-height: 2rem;
  padding: 0.25rem 0.7rem;
  font-size: 0.82rem;
  font-weight: 500;
}

.button--active {
  border-color: var(--blue);
  box-shadow: inset 0 0 0 1px var(--blue);
}

/* ---------- the capability elements themselves ----------
   Only properties Chrome allows on <usermedia>/<camera>/<microphone> are used
   here. Anything outside the allowlist is either corrected or, worse, makes the
   element refuse clicks — so this stays deliberately plain. */

.has-usermedia usermedia:not(#playgroundUserMedia),
.has-camera camera,
.has-microphone microphone {
  color: #ffffff;
  background-color: var(--brand);
  border: 2px solid var(--brand-dark);
  border-radius: 6px;
  font-size: 1rem;
  font-weight: 600;
  padding: 0.5rem 1.1rem;
}

.has-usermedia usermedia:not(#playgroundUserMedia):granted,
.has-camera camera:granted,
.has-microphone microphone:granted {
  background-color: var(--ok);
  border-color: #17603b;
}

.element-stage {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem;
  border: 1px dashed var(--line);
  border-radius: 6px;
  background: var(--panel);
  margin: 0 0 1rem;
  min-height: 4.5rem;
}

.element-stage--playground {
  position: relative;
  margin: 0;
  overflow: hidden;
}

.occluder {
  position: absolute;
  inset: 0.75rem;
  background: rgba(0, 90, 156, 0.75);
  border-radius: 4px;
  color: #fff;
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 0.5rem;
}

/* ---------- capture preview ---------- */

.capture {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
  margin-bottom: 20px;
}

@media (min-width: 48rem) {
  .capture {
    grid-template-columns: minmax(0, 22rem) minmax(0, 1fr);
    align-items: start;
  }
}

#videoContainer {
  position: relative;
  border-radius: 6px;
  overflow: hidden;
  background: #222;
  aspect-ratio: 4 / 3;
}

#videoContainer.is-audio-only {
  aspect-ratio: 16 / 5;
}

video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #222;
}

.mini-video {
  border-radius: 6px;
  overflow: hidden;
  background: #222;
  aspect-ratio: 4 / 3;
  margin: 0.5rem 0;
}

.audio-only-note {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 0.85rem;
  text-align: center;
  padding: 1rem;
  margin: 0;
}

#videoContainer.is-audio-only .audio-only-note {
  display: flex;
}

/* ---------- status / meter ---------- */

.status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  color: var(--muted);
  margin: 0;
}

.dot {
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  background: var(--muted);
  flex: none;
}

.status.is-live .dot {
  background: var(--brand);
  animation: pulse 1.2s ease-in-out infinite;
}

.status.is-live {
  color: var(--brand-dark);
  font-weight: 600;
}

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

@media (prefers-reduced-motion: reduce) {
  .status.is-live .dot {
    animation: none;
  }
}

.meter {
  height: 0.5rem;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}

.meter--tall {
  height: 0.75rem;
  margin: 0.5rem 0;
}

.meter > span {
  display: block;
  height: 100%;
  width: 0%;
  background: var(--blue);
  transition: width 80ms linear;
}

/* ---------- stats ---------- */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(6.5rem, 1fr));
  gap: 0.75rem;
  list-style: none;
  padding: 0;
  margin: 0;
}

.stats li {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.5rem 0.65rem;
  background: var(--panel);
}

.stats .stat-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.stats .stat-value {
  font-variant-numeric: tabular-nums;
  font-size: 1.05rem;
  font-weight: 600;
  overflow-wrap: anywhere;
}

/* ---------- support / property tables ---------- */

.support {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
  gap: 0.25rem 1.5rem;
  margin: 0;
  font-size: 0.88rem;
  margin-bottom: 20px;
}

.support div {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.3rem 0;
  border-bottom: 1px solid var(--line);
}

.support dt {
  color: var(--muted);
}

.support dd {
  margin: 0;
  text-align: right;
  font-weight: 600;
  min-width: 0;
  overflow-wrap: anywhere;
  font-variant-numeric: tabular-nums;
}

.support dd.yes {
  color: var(--ok);
}

.support dd.no {
  color: var(--brand-dark);
}

.support dd.partial {
  color: var(--warn);
}

/* ---------- data tables ---------- */

.table-scroll {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  margin-bottom: 20px;
}

.data-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.85rem;
  min-width: 30rem;
}

.data-table th,
.data-table td {
  text-align: left;
  vertical-align: top;
  padding: 0.45rem 0.7rem;
  border-bottom: 1px solid var(--line);
}

.data-table thead th {
  background: var(--panel);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  white-space: nowrap;
}

.data-table tbody tr:last-child td {
  border-bottom: 0;
}

.data-table td.is-corrected {
  color: var(--warn);
  font-weight: 600;
}

.data-table td.is-ok {
  color: var(--ok);
}

.data-table code {
  background: none;
  border: 0;
  padding: 0;
}

.data-table .why {
  color: var(--muted);
  font-size: 0.72rem;
  white-space: nowrap;
}

/* ---------- constraint sanitizer ---------- */

.sanitizer {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
  gap: 1rem;
  margin-top: 0.5rem;
}

.sanitizer-group {
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}

.sanitizer-group > h4 {
  margin: 0;
  padding: 0.35rem 0.7rem;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.sanitizer-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.5rem;
  padding: 0.3rem 0.7rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.76rem;
  border-bottom: 1px solid #ebeef1;
  align-items: baseline;
}

.sanitizer-row:last-child {
  border-bottom: 0;
}

.sanitizer-row .mark {
  font-weight: 700;
}

.sanitizer-row.is-kept {
  background: rgba(31, 122, 77, 0.07);
}

.sanitizer-row.is-kept .mark {
  color: var(--ok);
}

.sanitizer-row.is-dropped {
  background: rgba(237, 52, 29, 0.05);
}

.sanitizer-row.is-dropped .mark {
  color: var(--brand-dark);
}

.sanitizer-row .why {
  color: var(--muted);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 0.76rem;
}

.sanitizer-empty {
  padding: 0.5rem 0.7rem;
  color: var(--muted);
  font-size: 0.8rem;
  margin: 0;
}

/* ---------- track list ---------- */

.track-list {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  padding: 0.5rem 0.75rem;
}

.track-list .placeholder {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0;
}

.track {
  padding: 0.5rem 0;
  border-top: 1px solid var(--line);
}

.track:first-child {
  border-top: 0;
}

.track-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem;
  font-size: 0.9rem;
}

.track-kind {
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  color: #fff;
  background: var(--blue);
  border-radius: 3px;
  padding: 0.05rem 0.35rem;
}

.track-kind.is-audio {
  background: var(--brand-dark);
}

.track-label {
  font-weight: 600;
  min-width: 0;
  overflow-wrap: anywhere;
}

.track-flags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.3rem;
}

.flag {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.7rem;
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 0.05rem 0.3rem;
  background: #fff;
  color: var(--muted);
}

.flag.is-on {
  color: var(--ok);
  border-color: rgba(31, 122, 77, 0.4);
}

.flag.is-off {
  color: var(--brand-dark);
  border-color: rgba(237, 52, 29, 0.4);
}

.track-settings {
  margin-top: 0.35rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.74rem;
  color: var(--muted);
  overflow-wrap: anywhere;
}

/* ---------- code blocks ---------- */

.code-block {
  margin: 0 0 1rem;
  padding: 0.75rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow-x: auto;
  font-size: 0.8rem;
  line-height: 1.55;
}

.code-block code {
  background: none;
  border: 0;
  padding: 0;
  font-size: inherit;
  white-space: pre;
}

details.json-view {
  margin-top: 0.75rem;
}

details.json-view summary {
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 20px;
}

details.json-view pre {
  margin: 0.5rem 0 0;
  padding: 0.75rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  max-height: 20rem;
  overflow: auto;
  font-size: 0.8rem;
}

/* ---------- iframes ---------- */

.demo-frame {
  width: 100%;
  height: 15rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

/* ---------- event log ---------- */

.log-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.9rem;
  margin-bottom: 0.75rem;
}

.log-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  font-size: 0.82rem;
}

.log-filters label {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  cursor: pointer;
  white-space: nowrap;
}

.log-toolbar .spacer {
  flex: 1 1 auto;
}

.log {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.78rem;
  line-height: 1.5;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  max-height: 24rem;
  overflow: auto;
  padding: 0.4rem 0;
}

.log-empty {
  color: var(--muted);
  padding: 0.4rem 0.75rem;
  margin: 0;
}

.log-row {
  display: grid;
  grid-template-columns: auto 4.2rem 1fr;
  gap: 0.6rem;
  padding: 0.2rem 0.75rem;
  border-left: 3px solid transparent;
}

.log-row + .log-row {
  border-top: 1px solid #ebeef1;
}

.log-time {
  color: var(--muted);
  white-space: nowrap;
}

.log-level {
  text-transform: uppercase;
  font-size: 0.68rem;
  letter-spacing: 0.05em;
  align-self: center;
  color: var(--muted);
}

.log-message {
  min-width: 0;
  overflow-wrap: anywhere;
}

.log-detail {
  grid-column: 3;
  margin: 0.2rem 0 0.1rem;
  color: var(--muted);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 0.74rem;
}

.log-row.level-error {
  border-left-color: var(--brand);
  background: rgba(237, 52, 29, 0.05);
}

.log-row.level-error .log-level,
.log-row.level-error .log-message {
  color: var(--brand-dark);
}

.log-row.level-warn {
  border-left-color: var(--warn);
  background: rgba(138, 97, 0, 0.06);
}

.log-row.level-warn .log-level,
.log-row.level-warn .log-message {
  color: var(--warn);
}

.log-row.level-info {
  border-left-color: var(--link);
}

.log-row.level-debug .log-message {
  color: var(--muted);
}

.log.hide-error .log-row.level-error,
.log.hide-warn .log-row.level-warn,
.log.hide-info .log-row.level-info,
.log.hide-debug .log-row.level-debug {
  display: none;
}

/* ---------- notices ---------- */

.notice {
  border-left: 3px solid var(--warn);
  background: rgba(138, 97, 0, 0.06);
  padding: 0.75rem 1rem;
  border-radius: 0 6px 6px 0;
  margin: 0 0 1.25rem;
  font-size: 0.92rem;
}

.notice strong {
  color: var(--warn);
}

.notice.notice--error {
  border-left-color: var(--brand);
  background: rgba(237, 52, 29, 0.06);
}

.notice.notice--error strong {
  color: var(--brand-dark);
}

.notice.notice--ok {
  border-left-color: var(--ok);
  background: rgba(31, 122, 77, 0.06);
}

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

.notice p:last-child {
  margin-bottom: 0;
}

@media (max-width: 30rem) {
  body {
    padding: 1.25rem 0.9rem 3rem;
  }

  .card {
    padding: 0.9rem;
  }

  .button {
    flex: 1 1 100%;
  }

  .log-row {
    grid-template-columns: auto 1fr;
    gap: 0.2rem 0.5rem;
  }

  .log-message,
  .log-detail {
    grid-column: 1 / -1;
  }
}
