/* Porchlight: warm, calm, high contrast, big targets. No external fonts. */
:root {
  --cream: #fdf6ec;
  --ink: #2a1a0e;
  --amber: #a84a06;      /* white text on this: ~5.6:1 */
  --amber-dark: #7f3803;
  --night: #15100c;
  --panel: rgba(21, 16, 12, 0.88);
  --red: #b3261e;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --controls-h: 96px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--cream);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 20px;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; cursor: pointer; touch-action: manipulation; }
button:focus-visible, input:focus-visible { outline: 4px solid #f2b705; outline-offset: 3px; }

.screen { position: fixed; inset: 0; }

/* ---------- start screen ---------- */
.start {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: calc(24px + var(--safe-t)) calc(24px + var(--safe-r)) calc(24px + var(--safe-b)) calc(24px + var(--safe-l));
  text-align: center;
  background: radial-gradient(circle at 50% 30%, #fff8ee 0%, var(--cream) 55%, #f6e6cf 100%);
  overflow-y: auto;
}
.start h1 { margin: 0; font-size: clamp(2.2rem, 9vw, 3.4rem); font-weight: 700; letter-spacing: 0.02em; }
.start-msg { margin: 0; max-width: 28em; font-size: 1.3rem; font-weight: 600; }
.start-msg:empty { display: none; }
#start-form { display: flex; flex-direction: column; align-items: center; gap: 28px; width: 100%; }

.come-in {
  min-height: 112px;
  width: min(90vw, 460px);
  padding: 20px 28px;
  border: 0;
  border-radius: 28px;
  background: var(--amber);
  color: #fff;
  font-size: clamp(2rem, 8vw, 2.8rem);
  font-weight: 700;
  box-shadow: 0 10px 28px rgba(122, 56, 3, 0.35);
}
.come-in:active { background: var(--amber-dark); transform: translateY(2px); }
.come-in:disabled { opacity: 0.75; cursor: default; }

.name-field { display: flex; flex-direction: column; gap: 6px; font-size: 1rem; width: min(80vw, 320px); }
.name-field input {
  min-height: 56px;
  padding: 10px 14px;
  border: 2px solid #8a6a50;
  border-radius: 14px;
  background: #fff;
  color: var(--ink);
  font-size: 1.1rem;
  text-align: center;
}

/* ---------- call screen ---------- */
.call { background: var(--night); color: #fff; overflow: hidden; }

.remotes {
  position: absolute;
  top: 0; left: 0; right: 0;
  bottom: calc(var(--controls-h) + var(--safe-b));
  display: flex;
  flex-direction: column;     /* portrait: stacked */
  gap: 4px;
}
@media (orientation: landscape) {
  .remotes { flex-direction: row; } /* landscape: side by side */
}

.tile { position: relative; flex: 1 1 0; min-width: 0; min-height: 0; background: #2a211a; overflow: hidden; }
.tile video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; }
.tile.no-video video { display: none; }
.tile .avatar { display: none; }
.tile.no-video .avatar {
  display: flex;
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: min(60%, 60vmin, 280px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--amber);
  color: #fff;
  align-items: center;
  justify-content: center;
  padding: 8%;
  text-align: center;
  font-size: clamp(1.4rem, 6vmin, 2.4rem);
  font-weight: 700;
  overflow-wrap: anywhere;
  overflow: hidden;
}
.name-label {
  position: absolute;
  left: calc(10px + var(--safe-l));
  bottom: 10px;
  max-width: calc(100% - 20px);
  padding: 4px 12px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.6);
  font-size: 1.1rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tile.no-video .name-label { display: none; }

.alone {
  position: absolute;
  top: 0; left: 0; right: 0;
  bottom: calc(var(--controls-h) + var(--safe-b));
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 24px calc(24px + var(--safe-r)) 24px calc(24px + var(--safe-l));
  text-align: center;
  font-size: clamp(1.4rem, 5vw, 2rem);
  font-weight: 600;
}

/* self-view: small, corner, mirrored for the front camera */
.self {
  position: absolute;
  top: calc(12px + var(--safe-t));
  right: calc(12px + var(--safe-r));
  width: clamp(90px, 26vw, 180px);
  aspect-ratio: 3 / 4;
  border-radius: 14px;
  border: 2px solid rgba(255, 255, 255, 0.85);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
  overflow: hidden;
  z-index: 3;
}
@media (orientation: landscape) { .self { aspect-ratio: 4 / 3; width: clamp(110px, 20vw, 220px); } }
.self .tile { position: absolute; inset: 0; }
.self.mirror video { transform: scaleX(-1); }
.self .tile.no-video .avatar { width: 80%; font-size: 1rem; padding: 4%; }
.self .name-label { font-size: 0.8rem; bottom: 4px; left: 4px; }

.banner {
  position: absolute;
  top: calc(12px + var(--safe-t));
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  padding: 12px 24px;
  border-radius: 999px;
  background: #f2b705;
  color: #1a1206;
  font-size: 1.2rem;
  font-weight: 700;
  white-space: nowrap;
}

.notice {
  position: absolute;
  left: calc(12px + var(--safe-l));
  right: calc(12px + var(--safe-r));
  bottom: calc(var(--controls-h) + var(--safe-b) + 12px);
  z-index: 4;
  padding: 16px;
  border-radius: 18px;
  background: var(--cream);
  color: var(--ink);
  text-align: center;
  font-size: 1.15rem;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
}
.notice p { margin: 0 0 12px; }

.btn {
  min-height: 56px;
  padding: 8px 18px;
  border: 0;
  border-radius: 16px;
  background: var(--amber);
  color: #fff;
  font-weight: 700;
}

.controls {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: calc(var(--controls-h) + var(--safe-b));
  padding: 10px calc(10px + var(--safe-r)) calc(10px + var(--safe-b)) calc(10px + var(--safe-l));
  display: flex;
  gap: 10px;
  justify-content: center;
  background: #000;
  z-index: 4;
}
.ctl {
  flex: 1 1 0;
  max-width: 220px;
  min-height: 72px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: #3b2d22;
  color: #fff;
  font-size: 1rem;
  line-height: 1.1;
}
.ctl.muted { background: #f2b705; color: #1a1206; }
.ctl.leave { background: var(--red); }
.ctl:disabled { opacity: 0.6; }
.ico { width: 32px; height: 32px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ctl .ico-mic-off { display: none; }
.ctl.muted .ico-mic { display: none; }
.ctl.muted .ico-mic-off { display: block; }

/* stats (test build) */
.stats-toggle {
  position: absolute;
  top: calc(12px + var(--safe-t));
  left: calc(12px + var(--safe-l));
  z-index: 6;
  min-height: 44px;
  padding: 6px 12px;
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 10px;
  background: var(--panel);
  color: #fff;
  font-size: 0.8rem;
}
.stats {
  position: absolute;
  top: calc(62px + var(--safe-t));
  left: calc(12px + var(--safe-l));
  z-index: 6;
  max-width: min(92vw, 420px);
  max-height: 45vh;
  margin: 0;
  padding: 8px 10px;
  overflow: auto;
  border-radius: 10px;
  background: var(--panel);
  color: #e8ffe8;
  font: 11px/1.35 ui-monospace, Menlo, Consolas, monospace;
  white-space: pre-wrap;
}
.stats:empty { display: none; }

/* full-screen overlays */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(24px + var(--safe-t)) calc(24px + var(--safe-r)) calc(24px + var(--safe-b)) calc(24px + var(--safe-l));
  background: rgba(21, 16, 12, 0.92);
}
.overlay .come-in { font-size: clamp(1.6rem, 6vw, 2.4rem); }

@media (max-height: 460px) {
  :root { --controls-h: 80px; }
  .ctl { min-height: 60px; }
  .come-in { min-height: 80px; }
}
