/* The hidden attribute must win over the display rules below (rows and stages are flex
   boxes, which would otherwise stay visible). */
[hidden] {
  display: none !important;
}

:root {
  color-scheme: light dark;
  --fg: #1d1f21;
  --bg: #fafafa;
  --muted: #666;
  --accent: #2563eb;
  --card: #fff;
  --border: #ddd;
  --warn-bg: #fff4d6;
  --warn-fg: #6b4a00;
  --ok: #15803d;
  font-family: system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --fg: #e6e6e6;
    --bg: #16181b;
    --muted: #9aa0a6;
    --accent: #60a5fa;
    --card: #1f2226;
    --border: #33373d;
    --warn-bg: #3b2f10;
    --warn-fg: #f5d68a;
    --ok: #4ade80;
  }
}

body {
  margin: 0 auto;
  max-width: 44rem;
  padding: 1rem;
  color: var(--fg);
  background: var(--bg);
  line-height: 1.45;
}

h1 {
  margin: 0.2rem 0;
}

nav {
  display: flex;
  gap: 0.5rem;
  margin: 1rem 0;
}

nav button[aria-selected="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

section {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 0.6rem;
  padding: 1rem;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
  margin-bottom: 0.8rem;
}

label {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

select {
  max-width: 100%;
}

button {
  font: inherit;
  padding: 0.5rem 1rem;
  border-radius: 0.4rem;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--fg);
  cursor: pointer;
}

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

button:disabled {
  opacity: 0.5;
  cursor: default;
}

.progress {
  height: 0.8rem;
  border-radius: 0.4rem;
  background: var(--border);
  overflow: hidden;
}

#rx-bar {
  height: 100%;
  width: 0;
  background: var(--ok);
  transition: width 0.3s;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr));
  gap: 0.5rem;
}

.stats dt {
  color: var(--muted);
  font-size: 0.85rem;
}

.stats dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
}

.info {
  font-size: 0.9rem;
  color: var(--muted);
  padding-left: 1.2rem;
}

.info .bad,
.warn {
  color: var(--warn-fg);
}

.warn {
  background: var(--warn-bg);
  padding: 0.5rem 0.7rem;
  border-radius: 0.4rem;
}

.file {
  border: 1px solid var(--ok);
  border-radius: 0.5rem;
  padding: 0.6rem 0.8rem;
  margin: 0.8rem 0;
  word-break: break-all;
}

.file a {
  font-weight: bold;
}

pre {
  max-height: 16rem;
  overflow: auto;
  font-size: 0.8rem;
}

.hint,
footer {
  color: var(--muted);
  font-size: 0.9rem;
}

/* ---- visual channel page (visual.html) */

h1 small {
  font-size: 0.55em;
  font-weight: normal;
  color: var(--muted);
}

.camera {
  position: relative;
  background: #000;
  border-radius: 0.4rem;
  overflow: hidden;
  margin-bottom: 0.5rem;
}

.camera video,
.camera canvas {
  display: block;
  width: 100%;
  max-height: 60vh;
  object-fit: contain;
}

.camera canvas {
  position: absolute;
  inset: 0;
  height: 100%;
  max-height: none;
  pointer-events: none;
}

.stage {
  display: flex;
  flex-direction: column;
  background: #101424;
  border-radius: 0.4rem;
  margin: 0.8rem 0;
}

.stage canvas {
  display: block;
  width: 100%;
  aspect-ratio: 58 / 36;
}

.stage:fullscreen {
  border-radius: 0;
  margin: 0;
}

.stage:fullscreen canvas {
  flex: 1;
  aspect-ratio: auto;
  min-height: 0;
}

.stage p {
  margin: 0;
  padding: 0.2rem 0.6rem;
  color: #8a90a6;
  font-size: 0.8rem;
  text-align: center;
}

/* ---- "What is a data fountain?" box, in the header of both pages */

details.fountain {
  margin: 0.6rem 0;
  font-size: 0.95rem;
}

details.fountain summary {
  cursor: pointer;
  color: var(--accent);
}

details.fountain p {
  margin: 0.5rem 0 0;
}

/* ---- touch screens: bigger targets, no double-tap zoom delay */

button,
select,
input,
summary,
a {
  touch-action: manipulation;
}

button.small {
  padding: 0.3rem 0.7rem;
  font-size: 0.85rem;
}

@media (pointer: coarse) {
  button {
    padding: 0.65rem 1.1rem;
  }

  .row {
    gap: 0.9rem;
    margin-bottom: 1.1rem;
  }
}

/* ---- full views: the receiver's camera, the sender's picture or color.
   Fixed over the whole window, the page underneath cannot scroll (ui.js). */

body.immersed {
  overflow: hidden;
}

.immersive {
  position: fixed;
  inset: 0;
  z-index: 100;
  margin: 0;
  border-radius: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overscroll-behavior: contain;
}

.live.immersive {
  background: var(--bg);
}

.live.immersive .camera {
  flex: 1 1 auto;
  min-height: 0;
  margin: 0;
  border-radius: 0;
}

.live.immersive .camera video {
  height: 100%;
  max-height: none;
}

.live-status {
  padding-top: 0.6rem;
}

.live.immersive .live-status {
  flex: none;
  max-height: 50%;
  overflow: auto;
  padding: 0.6rem 0.8rem calc(0.6rem + env(safe-area-inset-bottom));
}

.live.immersive .live-status p {
  margin: 0.4rem 0;
}

.live.immersive .stats {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin: 0.4rem 0;
  font-size: 0.9rem;
}

.live.immersive .live-buttons {
  margin: 0.4rem 0 0;
  justify-content: space-between;
}

/* Nothing to scroll or zoom there; on iPhones a swipe would move the page below. */
.stage.immersive,
.live.immersive .camera {
  touch-action: none;
}

.stage.immersive canvas {
  flex: 1;
  aspect-ratio: auto;
  min-height: 0;
}

.stage-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0 0.4rem calc(0.2rem + env(safe-area-inset-bottom));
}

.stage-bar p {
  flex: 1;
  min-width: 0;
}

.stage-bar button {
  background: transparent;
  color: #8a90a6;
  border-color: #2a3046;
}

/* ---- light page (light.html) */

.small-camera video {
  max-height: 30vh;
}

.strip {
  display: block;
  width: 100%;
  height: 1.6rem;
  border-radius: 0.3rem;
  background: #000;
  image-rendering: pixelated;
}

.strip-caption {
  margin: 0.2rem 0 0.6rem;
  font-size: 0.8rem;
}

.progress.thin {
  height: 0.4rem;
  margin-top: 0.4rem;
}

#rx-frame-bar {
  height: 100%;
  width: 0;
  background: var(--accent);
}

.light-stage {
  min-height: 12rem;
  aspect-ratio: 16 / 9;
}

.light-stage.immersive {
  aspect-ratio: auto;
}

.light-fill {
  flex: 1;
}

.light-stage .stage-bar p,
.light-stage .stage-bar button {
  color: #eee;
  border-color: rgb(255 255 255 / 0.3);
}

/* ---- received messages and the text box of the Send tabs */

.message {
  margin: 0.5rem 0;
  padding: 0.5rem 0.7rem;
  background: var(--bg);
  border-radius: 0.4rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: normal;
  max-height: 40vh;
  overflow: auto;
  font-size: 1.05rem;
}

#tx-text {
  width: 100%;
  min-height: 4.5rem;
  font: inherit;
  padding: 0.5rem;
  border-radius: 0.4rem;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--fg);
  box-sizing: border-box;
}

#tx-text-row label {
  flex: 1;
}
