:root {
  --sky: #7dd3fc;
  --leaf: #4ade80;
  --bark: #a16207;
  --cream: #fefce8;
  --white: #fff;
  --text: #1c1917;
  --text-soft: #57534e;
  --shadow: rgba(0, 0, 0, 0.12);
  --radius: 16px;
  --radius-sm: 10px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: 'Nunito', sans-serif;
  background: linear-gradient(160deg, var(--sky) 0%, #bae6fd 40%, var(--cream) 100%);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}

.app {
  max-width: 1400px;
  margin: 0 auto;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.5rem;
  flex-shrink: 0;
}

.admin-link-wrap {
  margin-left: auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.15rem;
}

.admin-link {
  font-size: 0.9rem;
  color: var(--text-soft);
  text-decoration: none;
  font-weight: 600;
}

.admin-link:hover {
  color: var(--text);
}

.experimental-link {
  font-size: 0.78rem;
  font-weight: 700;
  color: #7c3aed;
  text-decoration: none;
  background: rgba(167, 139, 250, 0.15);
  padding: 0.15em 0.55em;
  border-radius: 20px;
  border: 1px solid rgba(124, 58, 237, 0.25);
  transition: background 0.15s;
}

.experimental-link:hover {
  background: rgba(167, 139, 250, 0.3);
}

.build-number {
  font-size: 0.65rem;
  color: var(--text-muted);
  opacity: 0.6;
  font-family: 'SF Mono', Monaco, Consolas, monospace;
  letter-spacing: 0.02em;
}

.logo {
  font-family: 'Fredoka', sans-serif;
  font-size: 1.75rem;
  font-weight: 600;
  margin: 0;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.logo-img {
  height: 3rem;
  width: auto;
  flex-shrink: 0;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.15));
}

.stat-icon-img {
  height: 2rem;
  width: auto;
  vertical-align: middle;
  flex-shrink: 0;
  filter: drop-shadow(0 1px 3px rgba(0,0,0,0.15));
}

.chat-title-img {
  height: 2rem;
  width: auto;
  vertical-align: middle;
  margin-right: 0.4rem;
  filter: drop-shadow(0 1px 3px rgba(0,0,0,0.15));
}

.snap-btn-img {
  height: 1.4rem;
  width: auto;
  vertical-align: middle;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.2));
}

.live-pill {
  background: var(--leaf);
  color: var(--white);
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  box-shadow: 0 2px 8px var(--shadow);
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.live-pill img {
  width: 1.1rem;
  height: 1.1rem;
  object-fit: contain;
}

.playback-pill {
  background: #f59e0b;
  color: var(--white);
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  box-shadow: 0 2px 8px var(--shadow);
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.playback-pill img {
  width: 1.1rem;
  height: 1.1rem;
  object-fit: contain;
}

.motion-status-pill {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.75rem;
  font-weight: 600;
  background: rgba(255,255,255,0.7);
  border: 1px solid rgba(0,0,0,0.1);
  border-radius: 20px;
  padding: 0.25em 0.75em;
}

.motion-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #9ca3af;
  flex-shrink: 0;
}

.motion-status-dot.connected  { background: var(--leaf); box-shadow: 0 0 0 3px rgba(74,222,128,0.25); }
.motion-status-dot.warming    { background: #facc15; animation: pulse-dot 1s infinite; }
.motion-status-dot.disconnected,
.motion-status-dot.offline    { background: #f87171; }

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

/* --- Stats strip (kid-friendly) --- */
.stats-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem 1.25rem;
  padding: 0.75rem 1.5rem;
  margin: 0 1rem 1rem;
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: 0 2px 12px var(--shadow);
  border: 2px solid rgba(74, 222, 128, 0.3);
}

.stats-streams {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.stats-streams .stats-label {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text-soft);
  margin-right: 0.25rem;
}

.stats-streams-list {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}

.stream-pill {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
  transition: transform 0.15s, box-shadow 0.15s;
}

.stream-pill-live {
  background: var(--leaf);
  color: var(--white);
  box-shadow: 0 2px 6px var(--shadow);
  animation: stream-pill-pulse 2s ease-in-out infinite;
}

.stream-pill-live:hover {
  transform: scale(1.05);
  box-shadow: 0 3px 10px var(--shadow);
}

.stream-pill-off {
  background: #e7e5e4;
  color: var(--text-soft);
}

@keyframes stream-pill-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.9; }
}

.stat-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.6rem;
  border-radius: var(--radius-sm);
  transition: background 0.15s, transform 0.15s;
}

.stat-item:hover {
  background: #f0fdf4;
  transform: translateY(-1px);
}

.stat-icon {
  font-size: 1.2rem;
  line-height: 1;
}

.stat-value {
  font-family: 'Fredoka', sans-serif;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
  min-width: 1.5ch;
  transition: transform 0.2s;
}

.stat-value.stat-bump {
  animation: stat-bump 0.4s ease-out;
}

@keyframes stat-bump {
  0% { transform: scale(1); }
  50% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

.stat-label {
  font-size: 0.85rem;
  color: var(--text-soft);
  font-weight: 600;
}

.stat-last-visit .stat-value {
  font-family: 'Nunito', sans-serif;
  font-size: 0.95rem;
  font-weight: 600;
}

.main {
  flex: 1;
  display: flex;
  gap: 1rem;
  padding: 0 1rem 1rem;
  min-height: 0;
  overflow: hidden;
}

.video-section {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: 0 4px 20px var(--shadow);
  overflow: hidden;
}

.camera-tabs-row {
  display: flex;
  align-items: stretch;
  background: var(--cream);
  border-bottom: 3px solid var(--leaf);
}

.camera-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  flex: 1;
  min-width: 0;
}

.camera-tabs [role="tab"] {
  font-family: 'Nunito', sans-serif;
  font-weight: 600;
  padding: 0.5rem 1rem;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--white);
  color: var(--text);
  cursor: pointer;
  font-size: 0.95rem;
  box-shadow: 0 2px 6px var(--shadow);
  transition: transform 0.15s, background 0.15s;
  min-height: 44px; /* touch-friendly tap target */
}

.camera-tabs [role="tab"]:hover {
  background: #fef9c3;
  transform: translateY(-1px);
}

.camera-tabs [role="tab"][aria-selected="true"] {
  background: var(--leaf);
  color: var(--white);
}

.video-wrap {
  position: relative;
  flex: 1;
  min-height: 220px;
  background: #0f172a;
}

.video-wrap video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.video-wrap.playback-mode video {
  /* Reduce letterboxing during recorded clip playback. */
  object-fit: cover;
}

.video-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.85);
  color: var(--cream);
  font-size: 1.1rem;
  padding: 1rem;
}

.video-overlay.hidden {
  display: none;
}

.playback-timestamp {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(245, 158, 11, 0.9);
  color: var(--white);
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  z-index: 5;
}

.playback-timestamp-icon {
  width: 2.4rem;
  height: 2.4rem;
  object-fit: contain;
}

.playback-timestamp.hidden {
  display: none;
}

.playback-ending-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  background: rgba(15, 23, 42, 0.9);
  color: var(--cream);
  z-index: 10;
}

.playback-ending-overlay.hidden {
  display: none;
}

.playback-ending-logo {
  width: 160px;
  height: 160px;
  object-fit: contain;
  animation: playback-logo-bounce 1s ease-in-out infinite;
}

@keyframes playback-logo-bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.playback-ending-overlay p {
  font-size: 1.2rem;
  font-weight: 600;
  margin: 0;
}

/* --- Snapshot & recordings area under main stream --- */
.snap-rec-wrap {
  padding: 0.5rem 0.75rem 0.75rem;
  background: var(--cream);
  border-top: 1px solid rgba(0,0,0,0.06);
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.snap-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Snapshot strip */
.snapshot-strip {
  display: flex;
  gap: 0.5rem;
  padding: 0.35rem 0.5rem;
  background: rgba(255,255,255,0.8);
  border-radius: var(--radius-sm);
  flex-shrink: 1;
  align-items: center;
  overflow-x: auto;
  flex-wrap: nowrap;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  width: 100%;
  box-sizing: border-box;
}
.snapshot-strip::-webkit-scrollbar { display: none; }
.snapshot-strip:empty {
  display: none;
}
.snap-thumb {
  position: relative;
  cursor: pointer;
  border-radius: 6px;
  overflow: hidden;
  border: 2px solid rgba(0,0,0,0.15);
  transition: border-color 0.15s, transform 0.15s;
  flex-shrink: 0;
}
.snap-thumb:hover {
  border-color: var(--leaf);
  transform: scale(1.04);
}
.snap-thumb img {
  width: 90px;
  height: 60px;
  object-fit: cover;
  display: block;
}
.snap-thumb-caption {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0,0,0,0.65);
  color: #fff;
  font-size: 0.6rem;
  padding: 0.15rem 0.3rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.snap-thumb--starred {
  border-color: #f6c90e;
  box-shadow: 0 0 0 2px rgba(246,201,14,0.35);
}
.snap-thumb--starred:hover {
  border-color: #f6c90e;
}
.snap-star-badge {
  position: absolute;
  top: 2px;
  left: 3px;
  font-size: 0.65rem;
  line-height: 1;
  text-shadow: 0 1px 3px rgba(0,0,0,0.7);
  pointer-events: none;
  z-index: 1;
}
.snap-strip-label {
  color: rgba(255,255,255,0.4);
  font-size: 0.75rem;
  margin-left: auto;
  white-space: nowrap;
}

/* --- Snapshot button --- */
.snap-btn {
  flex-shrink: 0;
  margin: 0;
  padding: 0.3rem 1.1rem 0.3rem 0.9rem;
  border: none;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
  color: #fff;
  font-size: 1.1rem;
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  letter-spacing: 0.01em;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  box-shadow: 0 4px 12px rgba(34,197,94,0.45), 0 1px 3px rgba(0,0,0,0.15);
  transition: transform 0.12s, box-shadow 0.12s, background 0.15s;
  white-space: nowrap;
  position: relative;
  overflow: hidden;
}
.snap-btn::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.35);
  pointer-events: none;
}
.snap-btn:hover {
  filter: brightness(1.1);
  box-shadow: 0 4px 16px rgba(34,197,94,0.6);
}
.snap-btn:active {
  filter: brightness(0.95);
  box-shadow: inset 0 2px 6px rgba(0,0,0,0.2);
}
.snap-btn.flash {
  background: linear-gradient(135deg, #fff 0%, #e0fce7 100%);
  box-shadow: 0 0 0 4px rgba(34,197,94,0.35), 0 4px 16px rgba(34,197,94,0.4);
}

/* --- Snapshot lightbox --- */
.snap-lightbox {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}
.snap-lightbox.hidden { display: none; }
.snap-lightbox-bg {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.85);
  cursor: pointer;
}
.snap-lightbox-inner {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  max-width: 90vw;
  max-height: 90vh;
}
.snap-lightbox-inner img {
  max-width: 100%;
  max-height: 75vh;
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.6);
}
#snap-lightbox-caption {
  color: rgba(255,255,255,0.85);
  font-size: 0.9rem;
  text-align: center;
}
#snap-lightbox-close {
  position: absolute;
  top: -1.5rem;
  right: -1rem;
  background: none;
  border: none;
  color: #fff;
  font-size: 1.4rem;
  cursor: pointer;
  line-height: 1;
  opacity: 0.7;
}
#snap-lightbox-close:hover { opacity: 1; }
.snap-lightbox-star {
  background: rgba(246,201,14,0.15);
  border: 2px solid #f6c90e;
  color: #f6c90e;
  border-radius: 6px;
  padding: 0.4rem 1rem;
  font-size: 0.95rem;
  cursor: pointer;
  font-family: 'Nunito', sans-serif;
  font-weight: 600;
  transition: background 0.15s;
}
.snap-lightbox-star:hover { background: rgba(246,201,14,0.3); }
.snap-lightbox-actions {
  display: flex;
  gap: 0.6rem;
  align-items: center;
}
.snap-lightbox-delete {
  background: rgba(239,68,68,0.15);
  border: 2px solid #ef4444;
  color: #fca5a5;
  border-radius: 6px;
  padding: 0.4rem 1rem;
  font-size: 0.95rem;
  cursor: pointer;
  font-family: 'Nunito', sans-serif;
  font-weight: 600;
  transition: background 0.15s;
}
.snap-lightbox-delete:hover { background: rgba(239,68,68,0.35); }

/* --- "All stars" strip button --- */
.snap-all-stars-btn {
  flex-shrink: 0;
  align-self: center;
  padding: 0.3rem 0.8rem;
  border: 2px solid #f6c90e;
  border-radius: 999px;
  background: rgba(246,201,14,0.12);
  color: #92400e;
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  font-size: 0.8rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, transform 0.12s;
}
.snap-all-stars-btn:hover {
  background: rgba(246,201,14,0.3);
  transform: scale(1.05);
}

/* --- All-stars modal --- */
.stars-modal {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
}
.stars-modal.hidden { display: none; }
.stars-modal-bg {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.8);
  cursor: pointer;
}
.stars-modal-inner {
  position: relative;
  z-index: 1;
  background: var(--white);
  border-radius: var(--radius);
  max-width: min(900px, 92vw);
  max-height: 85vh;
  width: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.stars-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 3px solid var(--leaf);
  background: var(--cream);
  flex-shrink: 0;
}
.stars-modal-header h2 {
  margin: 0;
  font-family: 'Fredoka', sans-serif;
  font-size: 1.25rem;
  color: var(--text);
}
#stars-modal-close {
  background: none;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  opacity: 0.6;
  line-height: 1;
  padding: 0.25rem;
}
#stars-modal-close:hover { opacity: 1; }
.stars-modal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.75rem;
  padding: 1rem;
  overflow-y: auto;
}
.stars-modal-grid .snap-thumb img {
  width: 100%;
  height: 110px;
}

.info-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.6);
  background: rgba(0,0,0,0.5);
  color: #fff;
  font-family: 'Fredoka', serif;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  min-height: 52px;
  min-width: 44px;
}
.info-btn:hover {
  background: rgba(0,0,0,0.7);
}

.info-panel {
  position: absolute;
  top: 0.5rem;
  right: 3rem;
  background: rgba(0,0,0,0.85);
  color: #e2e8f0;
  font-size: 0.8rem;
  font-family: 'SF Mono', Monaco, Consolas, monospace;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  z-index: 10;
  max-width: 300px;
  line-height: 1.5;
  white-space: pre-line;
}
.info-panel.hidden {
  display: none;
}

/* --- Fullscreen button --- */
.fullscreen-btn {
  position: absolute;
  bottom: 0.5rem;
  right: 0.5rem;
  background: rgba(0,0,0,0.5);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.3rem 0.5rem;
  min-height: 36px;
  min-width: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  z-index: 5;
}
.fullscreen-btn:hover {
  background: rgba(0,0,0,0.75);
}

.chat-section {
  width: 320px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: 0 4px 20px var(--shadow);
  overflow: hidden;
  min-height: 0;
  max-height: 100%;
}

.chat-title {
  font-family: 'Fredoka', sans-serif;
  font-size: 1.25rem;
  margin: 0;
  padding: 1rem;
  background: var(--cream);
  border-bottom: 3px solid var(--leaf);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* --- Chat bubbles --- */
.chat-msg-row {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  max-width: 100%;
}

.chat-msg-row--mine {
  flex-direction: row-reverse;
}

.chat-avatar {
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.25);
  box-shadow: 0 2px 4px rgba(0,0,0,0.15);
}

.chat-bubble {
  max-width: 75%;
  padding: 0.55rem 0.85rem 0.4rem;
  border-radius: 18px 18px 18px 4px;
  background: var(--white);
  border: 2px solid #e7e5e4;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  word-break: break-word;
}

.chat-bubble--mine {
  border-radius: 18px 18px 4px 18px;
  background: var(--leaf);
  border-color: #22c55e;
  color: #fff;
}

.chat-bubble-name {
  font-weight: 700;
  font-size: 0.8rem;
  margin-bottom: 0.15rem;
}

.chat-bubble-text {
  font-size: 0.95rem;
  line-height: 1.4;
}

.chat-bubble--mine .chat-bubble-text {
  color: #fff;
}

.chat-bubble-time {
  font-size: 0.7rem;
  color: var(--text-soft);
  margin-top: 0.2rem;
  text-align: right;
}

.chat-bubble--mine .chat-bubble-time {
  color: rgba(255,255,255,0.75);
}

.chat-input-wrap {
  padding: 1rem;
  background: var(--cream);
  border-top: 2px solid #e7e5e4;
  position: relative;
  min-width: 0;
}

.chat-nickname {
  flex: 1;
  min-width: 0;
  padding: 0.5rem 0.75rem;
  border: 2px solid #e7e5e4;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: inherit;
}

.chat-identity-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.btn-chat-webauthn {
  padding: 0.5rem 0.75rem;
  border: 2px solid #e7e5e4;
  border-radius: var(--radius-sm);
  background: #f5f5f4;
  cursor: pointer;
  font-size: 1.1rem;
  transition: background 0.15s, border-color 0.15s;
}

.btn-chat-webauthn:hover {
  background: #e7e5e4;
  border-color: #d6d3d1;
}

.btn-chat-webauthn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.chat-webauthn-status {
  font-size: 0.85rem;
  padding: 0.4rem 0.6rem;
  border-radius: var(--radius-sm);
  background: #d1fae5;
  color: #065f46;
  margin-top: 0.5rem;
}

.chat-webauthn-status.error {
  background: #fee2e2;
  color: #991b1b;
}

.chat-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  min-width: 0;
}

.chat-input {
  flex: 1;
  min-width: 0;
  padding: 0.6rem 0.75rem;
  border: 2px solid #e7e5e4;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: inherit;
}

.chat-input:focus,
.chat-nickname:focus {
  outline: none;
  border-color: var(--leaf);
}

.btn-send {
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  padding: 0.6rem 1rem;
  border: none;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  white-space: nowrap;
  min-width: 4.5em;
  background: var(--leaf);
  color: var(--white);
  cursor: pointer;
  font-size: 0.95rem;
  transition: transform 0.15s, background 0.15s;
  min-height: 44px; /* touch-friendly tap target */
}

.btn-send:hover {
  background: #22c55e;
  transform: scale(1.02);
}

.btn-emoji {
  padding: 0.4rem 0.6rem;
  border: 2px solid #e7e5e4;
  border-radius: var(--radius-sm);
  background: var(--white);
  font-size: 1.25rem;
  cursor: pointer;
  min-height: 44px;
  line-height: 1;
  transition: background 0.15s;
  flex-shrink: 0;
}
.btn-emoji:hover {
  background: #fef9c3;
}

.emoji-picker {
  position: absolute;
  bottom: calc(100% + 0.5rem);
  right: 0;
  background: var(--white);
  border: 2px solid #e7e5e4;
  border-radius: var(--radius);
  padding: 0.5rem;
  width: 300px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.15);
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.emoji-picker.hidden {
  display: none;
}

.emoji-search-wrap {
  padding: 0 0.1rem;
}
.emoji-search {
  width: 100%;
  padding: 0.4rem 0.65rem;
  border: 2px solid #e7e5e4;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-family: inherit;
  box-sizing: border-box;
}
.emoji-search:focus {
  outline: none;
  border-color: var(--leaf);
}

.emoji-tab-bar {
  display: flex;
  gap: 0.15rem;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 0.1rem;
}
.emoji-tab-bar::-webkit-scrollbar { display: none; }
.emoji-tab {
  background: none;
  border: 2px solid transparent;
  border-radius: 8px;
  font-size: 1.15rem;
  cursor: pointer;
  padding: 0.2rem 0.3rem;
  flex-shrink: 0;
  line-height: 1;
  transition: background 0.1s, border-color 0.1s;
}
.emoji-tab:hover { background: #f0fdf4; }
.emoji-tab.active {
  background: #f0fdf4;
  border-color: var(--leaf);
}

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 0.1rem;
  max-height: 220px;
  overflow-y: auto;
  scrollbar-width: thin;
}
.emoji-grid button {
  background: none;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  padding: 0.2rem;
  border-radius: 6px;
  line-height: 1;
  transition: background 0.1s, transform 0.1s;
  text-align: center;
}
.emoji-grid button:hover {
  background: #f0fdf4;
  transform: scale(1.2);
}

.rec-toggle-btn {
  font-family: 'Nunito', sans-serif;
  font-weight: 600;
  font-size: 0.9rem;
  padding: 0.4rem 0.85rem;
  border: 2px solid var(--leaf);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  min-height: 44px;
  transition: background 0.15s, color 0.15s;
}
.rec-toggle-btn:hover, .rec-toggle-btn.active {
  background: var(--leaf);
  color: var(--white);
}

.recordings-panel {
  width: 100%;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: rgba(255,255,255,0.95);
  border-radius: var(--radius-sm);
  box-shadow: 0 2px 10px var(--shadow);
  overflow: hidden;
  max-height: 320px;
}
.recordings-panel.hidden { display: none; }

/* Recent recordings strip (preview of last clips) */
.rec-strip {
  display: flex;
  gap: 0.35rem;
  padding: 0.4rem 0.1rem 0;
  overflow-x: auto;
  flex-wrap: nowrap;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.rec-strip::-webkit-scrollbar { display: none; }
.rec-strip:empty {
  display: none;
}

.rec-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  border: 1px solid rgba(0,0,0,0.08);
  background: rgba(255,255,255,0.9);
  font-size: 0.8rem;
  cursor: pointer;
  position: relative;
  white-space: nowrap;
}
.rec-chip-time {
  font-weight: 600;
  color: var(--text);
}
.rec-chip-meta {
  color: var(--text-soft);
  font-size: 0.75rem;
}
.rec-chip-star {
  font-size: 0.8rem;
  color: rgba(0,0,0,0.25);
}
.rec-chip-star-on {
  color: #f6c90e;
}
.rec-chip-delete {
  font-size: 0.9rem;
  color: rgba(0,0,0,0.3);
  margin-left: 0.15rem;
  cursor: pointer;
}
.rec-chip-delete:hover {
  color: #e74c3c;
}

.rec-chip-state {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  pointer-events: none;
}

.rec-chip--state-active .rec-chip-time,
.rec-chip--state-active .rec-chip-meta,
.rec-chip--state-active .rec-chip-star {
  opacity: 0;
  pointer-events: none;
}

.recordings-controls {
  display: flex;
  gap: 0.4rem;
  padding: 0.75rem 1rem;
  background: var(--cream);
  border-bottom: 2px solid #e7e5e4;
  flex-wrap: wrap;
}

.rec-date-input, .rec-camera-select {
  flex: 1;
  min-width: 0;
  padding: 0.4rem 0.5rem;
  border: 2px solid #e7e5e4;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-family: inherit;
}
.rec-date-input:focus, .rec-camera-select:focus {
  outline: none;
  border-color: var(--leaf);
}

.btn-rec-search {
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  padding: 0.4rem 0.75rem;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--leaf);
  color: var(--white);
  cursor: pointer;
  font-size: 0.875rem;
  min-height: 36px;
}
.btn-rec-search:hover { background: #22c55e; }

.rec-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.rec-empty, .rec-error {
  color: var(--text-soft);
  font-size: 0.9rem;
  text-align: center;
  padding: 1rem 0;
  margin: 0;
}
.rec-error { color: #e53e3e; }

.rec-clip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  background: #f0fdf4;
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--leaf);
  padding: 0.35rem 0.6rem;
}

.rec-clip-info {
  display: flex;
  flex-direction: column;
  gap: 0.05rem;
  min-width: 0;
}

.rec-time {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text);
}

.rec-dur, .rec-size {
  font-size: 0.75rem;
  color: var(--text-soft);
}

.btn-play-clip {
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  padding: 0.25rem 0.55rem;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--leaf);
  color: var(--white);
  cursor: pointer;
  font-size: 0.8rem;
  white-space: nowrap;
  min-height: 30px;
  flex-shrink: 0;
  transition: background 0.15s;
}
.btn-play-clip:hover { background: #22c55e; }
.btn-play-clip:disabled { background: #a0aec0; cursor: default; }

/* Tablet & small desktop */
@media (max-width: 900px) {
  .app {
    height: auto;
    min-height: 100vh;
  }
  .main {
    overflow: visible;
  }
  .stats-strip {
    margin: 0 0.5rem 0.75rem;
    padding: 0.6rem 1rem;
    gap: 0.75rem 1rem;
  }
  .main {
    flex-direction: column;
  }
  .video-section {
    flex-shrink: 0;
  }
  .video-wrap {
    aspect-ratio: 16/9;
    min-height: 200px;
  }
  .chat-section {
    width: 100%;
    flex-shrink: 0;
    max-height: 320px;
  }
}

/* Phone landscape & small tablets */
@media (max-width: 600px) {
  .stats-strip {
    margin: 0 0.5rem 0.5rem;
    padding: 0.4rem 0.75rem;
    gap: 0.4rem 0.6rem;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .stats-strip::-webkit-scrollbar { display: none; }
  .stat-value {
    font-size: 1rem;
  }
  .stat-label {
    font-size: 0.8rem;
  }
  .stat-last-visit .stat-value {
    font-size: 0.85rem;
  }
  .header {
    padding: 0.6rem 1rem;
  }
  .logo {
    font-size: 1.35rem;
  }
  .main {
    padding: 0 0.5rem 0.5rem;
    gap: 0.5rem;
  }
  .video-section {
    border-radius: var(--radius-sm);
    flex-shrink: 0;
  }
  .video-wrap {
    aspect-ratio: 16/9;
    min-height: 180px;
  }
  .camera-tabs {
    padding: 0.5rem;
    gap: 0.35rem;
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
  }
  .camera-tabs [role="tab"] {
    padding: 0.45rem 0.85rem;
    font-size: 0.875rem;
    white-space: nowrap;
    flex-shrink: 0;
  }
  .chat-section {
    border-radius: var(--radius-sm);
    flex-shrink: 0;
    max-height: 300px;
  }
  .chat-title {
    padding: 0.6rem 1rem;
    font-size: 1rem;
  }
  .chat-messages {
    padding: 0.6rem;
  }
  .chat-input-wrap {
    padding: 0.6rem;
  }
  .chat-nickname {
    font-size: 16px; /* prevents iOS zoom on focus */
  }
  .chat-input {
    font-size: 16px; /* prevents iOS zoom on focus */
  }
  .btn-send {
    padding: 0.6rem 0.85rem;
    font-size: 0.9rem;
  }
}

/* Phone portrait */
@media (max-width: 400px) {
  .stats-strip {
    margin: 0 0.35rem 0.35rem;
    padding: 0.35rem 0.5rem;
    gap: 0.35rem 0.5rem;
  }
  .stat-icon-img {
    height: 1.4rem;
  }
  .stream-pill {
    font-size: 0.75rem;
    padding: 0.15rem 0.5rem;
  }
  .header {
    padding: 0.4rem 0.75rem;
  }
  .logo {
    font-size: 1.1rem;
  }
  .logo-img {
    height: 2.2rem;
  }
  .live-pill {
    font-size: 0.75rem;
    padding: 0.2rem 0.6rem;
  }
  .main {
    padding: 0 0.35rem 0.35rem;
    gap: 0.35rem;
  }
  .video-wrap {
    aspect-ratio: 16/9;
    min-height: 160px;
  }
  .chat-section {
    max-height: 260px;
  }
}

/* Landscape phones – prioritize video, keep chat side-by-side */
@media (max-height: 500px) and (orientation: landscape) {
  .app {
    height: 100vh;
  }
  .header {
    padding: 0.4rem 1rem;
  }
  .logo {
    font-size: 1.1rem;
  }
  .main {
    flex-direction: row;
    padding: 0 0.5rem 0.5rem;
  }
  .video-section {
    flex: 1;
  }
  .chat-section {
    width: 260px;
    max-height: none;
  }
  .video-wrap {
    min-height: 0;
  }
}
