/* Web Clip Playground — iOS-flavoured grouped-list UI.
   Dark is the default; light mode mirrors iOS system greys. */

:root {
  color-scheme: dark light;

  --bg: #0a0c1a;
  --bg-elevated: #151a2e;
  --card: #131829;
  --card-inset: #0e1220;
  --text: #e8ecf5;
  --text-muted: #8b93ad;
  --separator: rgba(255, 255, 255, 0.08);
  --accent: #7c9cff;
  --accent-text: #0a0c1a;

  --pass: #34d399;
  --fail: #f87171;
  --blocked: #fbbf24;
  --unsupported: #7c839b;
  --present: #60a5fa;

  --radius: 14px;
  --pad: 16px;

  /* Resolved once here so probes and layout share the same values. */
  --sat: env(safe-area-inset-top, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f2f2f7;
    --bg-elevated: #ffffff;
    --card: #ffffff;
    --card-inset: #f2f2f7;
    --text: #1c1c1e;
    --text-muted: #6b7280;
    --separator: rgba(0, 0, 0, 0.08);
    --accent: #3b5bdb;
    --accent-text: #ffffff;
    --unsupported: #8e8e93;
  }
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
    system-ui, sans-serif;
  /* Stop the whole page rubber-banding like a web page; feels more app-like. */
  overscroll-behavior-y: none;
  -webkit-text-size-adjust: 100%;
  padding-left: var(--sal);
  padding-right: var(--sar);
}

/* ---------- top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  padding-top: var(--sat);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--separator);
}

.topbar-inner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px var(--pad);
}

.topbar-title {
  flex: 1;
  min-width: 0;
}

.topbar h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.install-state {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.install-state.is-installed {
  color: var(--pass);
}

/* One row that scrolls sideways rather than wrapping — a two-line tally makes
   the sticky header eat a third of a phone screen. */
.tally {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  padding: 0 var(--pad) 10px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.tally::-webkit-scrollbar {
  display: none;
}

.tally .pill {
  font-size: 10px;
  padding: 3px 8px;
  white-space: nowrap;
}

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

.btn {
  flex: none;
  appearance: none;
  border: 1px solid var(--separator);
  border-radius: 980px;
  padding: 8px 16px;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  background: var(--bg-elevated);
  color: var(--text);
  cursor: pointer;
  /* Suppress the iOS tap flash; :active handles feedback instead. */
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.btn:active {
  opacity: 0.55;
}

.btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-text);
  border-color: transparent;
}

.btn-sm {
  padding: 6px 13px;
  font-size: 14px;
}

/* ---------- groups & cards ---------- */

.groups {
  padding: 8px 0 24px;
}

.loading {
  padding: 32px var(--pad);
  color: var(--text-muted);
  text-align: center;
}

.group {
  margin: 20px 0 0;
}

.group-head {
  padding: 0 var(--pad) 8px;
}

.group-head h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.group-head p {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--text-muted);
}

.group-cards {
  margin: 0 var(--pad);
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
}

.card {
  padding: 12px 14px;
  border-top: 1px solid var(--separator);
}

.card:first-child {
  border-top: none;
}

.card-head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.card-title {
  flex: 1;
  min-width: 0;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.card-note {
  margin: 6px 0 0;
  font-size: 13px;
  line-height: 1.4;
  color: var(--text-muted);
}

.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.card-mount:not(:empty) {
  margin-top: 10px;
}

.card-log:not(:empty),
.code-block {
  margin-top: 10px;
  padding: 9px 11px;
  background: var(--card-inset);
  border-radius: 9px;
  font: 12px/1.5 ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  color: var(--text-muted);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 220px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Copy-paste target, so let the OS text selection work on it. */
.code-block {
  user-select: all;
  -webkit-user-select: all;
  color: var(--text);
}

.card-log .log-err {
  color: var(--fail);
}

.card-log .log-ok {
  color: var(--pass);
}

/* ---------- status pills ---------- */

.pill {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 980px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: color-mix(in srgb, var(--pill-colour) 18%, transparent);
  color: var(--pill-colour);
  --pill-colour: var(--unsupported);
}

.pill::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.pill[data-status="pass"] { --pill-colour: var(--pass); }
.pill[data-status="fail"] { --pill-colour: var(--fail); }
.pill[data-status="blocked"] { --pill-colour: var(--blocked); }
.pill[data-status="unsupported"] { --pill-colour: var(--unsupported); }
.pill[data-status="present"] { --pill-colour: var(--present); }
.pill[data-status="missing"] { --pill-colour: var(--unsupported); }
.pill[data-status="running"] { --pill-colour: var(--accent); }
.pill[data-status="untested"] { --pill-colour: var(--text-muted); }

/* ---------- readouts (used by env-style probes) ---------- */

.readout {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 14px;
  font-size: 13px;
}

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

.readout dd {
  margin: 0;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  font-size: 12px;
  word-break: break-word;
}

/* Visualises the four safe-area insets as a real box. */
.inset-box {
  position: relative;
  height: 128px;
  border-radius: 10px;
  background: var(--card-inset);
  border: 1px solid var(--separator);
  overflow: hidden;
}

.inset-box .inset-fill {
  position: absolute;
  inset: 0;
  border-style: solid;
  border-color: color-mix(in srgb, var(--accent) 35%, transparent);
  /* Border widths are set inline from the live env() values. */
}

.inset-box .inset-safe {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 11px;
  color: var(--text-muted);
}

/* ---------- support wall ---------- */

.support-list {
  display: grid;
  gap: 10px;
}

.support-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 8px;
  align-items: center;
}

.support-name {
  font-size: 14px;
  font-weight: 600;
}

.support-why {
  grid-column: 1 / -1;
  margin: 0;
  font-size: 12px;
  line-height: 1.4;
  color: var(--text-muted);
}

/* ---------- media & sensor readouts ---------- */

.preview {
  display: block;
  width: 100%;
  max-height: 300px;
  border-radius: 10px;
  background: #000;
  object-fit: cover;
}

.meter {
  height: 10px;
  border-radius: 5px;
  background: var(--card-inset);
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  width: 0%;
  border-radius: 5px;
  background: linear-gradient(90deg, var(--pass), var(--blocked), var(--fail));
  transition: width 0.06s linear;
}

/* Three axis bars for the orientation readout. */
.axes {
  display: grid;
  gap: 6px;
}

.axis {
  display: grid;
  grid-template-columns: 4ch 1fr 7ch;
  align-items: center;
  gap: 8px;
  font: 12px/1 ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  color: var(--text-muted);
}

.axis-track {
  position: relative;
  height: 8px;
  border-radius: 4px;
  background: var(--card-inset);
}

/* Grows from the centre so negative values read naturally. */
.axis-bar {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 0;
  border-radius: 4px;
  background: var(--accent);
}

/* ---------- footer ---------- */

.footer {
  padding: 8px var(--pad) calc(28px + var(--sab));
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-muted);
}

.footer p {
  margin: 0 0 6px;
}

.footer-sw {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}

@media (prefers-reduced-motion: no-preference) {
  .pill {
    transition: background-color 0.2s ease, color 0.2s ease;
  }
}
