:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", sans-serif;
  background: #eef1ef;
  color: #18211e;
  font-synthesis: none;
  letter-spacing: 0;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  background: #eef1ef;
}

button,
input {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  width: min(100%, 540px);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 18px
    max(30px, env(safe-area-inset-bottom));
}

.topbar,
.section-heading,
.control-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar {
  min-height: 62px;
  margin-bottom: 22px;
}

.eyebrow,
.section-kicker {
  margin: 0 0 3px;
  color: #68736f;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: 0;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 25px;
  line-height: 1.2;
}

h2 {
  margin-bottom: 0;
  font-size: 17px;
  line-height: 1.35;
}

.device-state {
  display: flex;
  min-height: 34px;
  align-items: center;
  gap: 7px;
  padding: 0 10px;
  border: 1px solid #c8d7d0;
  border-radius: 6px;
  background: #f8fbf9;
  color: #296747;
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
}

.status-dot,
.live-indicator > span {
  width: 7px;
  height: 7px;
  flex: 0 0 7px;
  border-radius: 50%;
  background: #28a66a;
  box-shadow: 0 0 0 3px rgba(40, 166, 106, 0.13);
}

.device-state.offline {
  border-color: #e0cac6;
  color: #9b473d;
}

.device-state.offline .status-dot {
  background: #c65b4e;
  box-shadow: 0 0 0 3px rgba(198, 91, 78, 0.13);
}

.section-heading {
  align-items: flex-end;
  margin-bottom: 11px;
}

.icon-button {
  display: grid;
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  place-items: center;
  border: 1px solid #d2d9d6;
  border-radius: 7px;
  background: #ffffff;
  color: #26312d;
  font-size: 22px;
  line-height: 1;
}

.icon-button:active,
.primary-button:active {
  transform: translateY(1px);
}

.stream-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  margin: 0;
  overflow: hidden;
  border-radius: 8px;
  background: #151b19;
  box-shadow: 0 10px 26px rgba(15, 24, 20, 0.14);
}

.stream-frame > video,
.stream-frame > img {
  display: block;
  width: 100%;
  height: 100%;
  background: #111714;
  object-fit: contain;
}

.stream-frame > [hidden] {
  display: none;
}

.stream-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  align-content: center;
  justify-items: center;
  padding: 24px;
  background: #151b19;
  color: #e7ece9;
  text-align: center;
}

.stream-placeholder::before {
  width: 48px;
  height: 34px;
  margin-bottom: 15px;
  border: 2px solid #82908a;
  border-radius: 6px;
  box-shadow: inset 0 0 0 11px #151b19, inset 0 0 0 13px #82908a;
  content: "";
}

.stream-placeholder strong,
.stream-placeholder span {
  display: block;
}

.stream-placeholder strong {
  font-size: 15px;
  line-height: 1.5;
}

.stream-placeholder span {
  margin-top: 4px;
  color: #98a39f;
  font-size: 12px;
  line-height: 1.5;
}

.stream-meta {
  position: absolute;
  top: 11px;
  right: 11px;
  left: auto;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 9px;
  color: rgba(255, 255, 255, 0.9);
  font-size: 10px;
  font-weight: 700;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.55);
}

.live-indicator {
  display: flex;
  min-height: 25px;
  align-items: center;
  gap: 7px;
  padding: 0 8px;
  border-radius: 5px;
  background: rgba(16, 23, 20, 0.78);
}

.live-indicator > span {
  background: #ef6558;
  box-shadow: 0 0 0 3px rgba(239, 101, 88, 0.16);
}

.detection-box {
  position: absolute;
  left: 14%;
  top: 12%;
  width: 72%;
  height: 78%;
  border: 2px solid #72e2a8;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.18);
  transition: inset 220ms ease, width 220ms ease, height 220ms ease;
}

.detection-box::before,
.detection-box::after {
  position: absolute;
  width: 16px;
  height: 16px;
  border-color: #ffffff;
  content: "";
}

.detection-box::before {
  top: -2px;
  left: -2px;
  border-top: 3px solid;
  border-left: 3px solid;
}

.detection-box::after {
  right: -2px;
  bottom: -2px;
  border-right: 3px solid;
  border-bottom: 3px solid;
}

.detection-box > span {
  position: absolute;
  top: -30px;
  left: -2px;
  min-height: 28px;
  padding: 5px 8px;
  border-radius: 4px 4px 4px 0;
  background: #64d59b;
  color: #10251b;
  font-size: 12px;
  font-weight: 800;
  line-height: 18px;
  white-space: nowrap;
}

.snapshot-box {
  pointer-events: none;
  transition: left 250ms linear, top 250ms linear, width 250ms linear, height 250ms linear;
}

.snapshot-box > span {
  top: 0;
  font-size: 11px;
}

.snapshot-box.predicted {
  border-style: dashed;
}

.stream-footer {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
  min-height: 43px;
  align-items: center;
  justify-content: space-between;
  padding: 0 13px;
  background: rgba(13, 20, 17, 0.76);
  color: #e8eeeb;
  font-size: 12px;
}

.recognition-status {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  min-height: 42px;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  border-bottom: 1px solid #d5dcd9;
  color: #68736f;
  font-size: 12px;
}

.recognition-status strong {
  color: #26312d;
  font-size: 14px;
}

.recognition-status strong.action-eating {
  color: #b44d35;
}

.recognition-status strong.action-drinking {
  color: #24739a;
}

.recognition-status > span:last-child {
  color: #43514c;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.care-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  margin-top: 14px;
  border-top: 1px solid #d5dcd9;
  border-bottom: 1px solid #d5dcd9;
  background: #d5dcd9;
}

.care-metric {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  min-width: 0;
  align-items: center;
  gap: 11px;
  padding: 16px 12px;
  background: #f4f6f5;
}

.care-metric > div {
  min-width: 0;
}

.care-metric > div > span,
.care-metric strong,
.care-metric time {
  display: block;
}

.care-metric > div > span {
  color: #727c78;
  font-size: 11px;
  line-height: 1.3;
}

.care-metric strong {
  display: flex;
  min-height: 35px;
  align-items: baseline;
  gap: 4px;
  color: #1d2824;
  font-size: 27px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.care-metric strong small {
  color: #5e6965;
  font-size: 11px;
  font-weight: 650;
}

.care-metric time {
  color: #7a8580;
  font-size: 10px;
  line-height: 1.3;
  white-space: nowrap;
}

.care-icon {
  position: relative;
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 7px;
  background: #e1ebe5;
}

.care-icon::before,
.care-icon::after {
  position: absolute;
  content: "";
}

.eating .care-icon::before {
  bottom: 10px;
  width: 22px;
  height: 9px;
  border: 2px solid #397455;
  border-top: 0;
  border-radius: 0 0 10px 10px;
}

.eating .care-icon::after {
  top: 10px;
  width: 18px;
  height: 7px;
  border-bottom: 2px solid #397455;
  border-radius: 50%;
}

.drinking .care-icon {
  background: #e2eaed;
}

.drinking .care-icon::before {
  width: 14px;
  height: 19px;
  border-radius: 9px 9px 10px 10px;
  background: #4b788a;
  clip-path: polygon(50% 0, 100% 56%, 100% 72%, 88% 91%, 68% 100%, 32% 100%, 12% 91%, 0 72%, 0 56%);
}

.control-section,
.history-section {
  margin-top: 24px;
}

.control-section {
  padding: 18px 0;
  border-top: 1px solid #d5dcd9;
  border-bottom: 1px solid #d5dcd9;
}

.control-row p {
  margin: 4px 0 0;
  color: #68736f;
  font-size: 12px;
  line-height: 1.45;
}

.camera-badge {
  min-width: 54px;
  padding: 5px 8px;
  border-radius: 5px;
  background: #e4e8e6;
  color: #69736f;
  font-size: 11px;
  font-weight: 700;
  text-align: center;
}

.camera-badge.active {
  background: #dcece3;
  color: #28704d;
}

.primary-button {
  display: flex;
  width: 100%;
  min-height: 46px;
  align-items: center;
  justify-content: center;
  gap: 9px;
  margin-top: 17px;
  border: 0;
  border-radius: 7px;
  background: #17201d;
  color: #ffffff;
  font-size: 15px;
  font-weight: 750;
}

.primary-button.active {
  border: 1px solid #c7d0cc;
  background: #ffffff;
  color: #8b3e36;
}

.primary-button:disabled {
  cursor: wait;
  opacity: 0.68;
}

.camera-button-icon {
  position: relative;
  width: 19px;
  height: 14px;
  border: 2px solid currentColor;
  border-radius: 3px;
}

.camera-button-icon::after {
  position: absolute;
  top: 2px;
  right: -7px;
  width: 6px;
  height: 7px;
  border: 2px solid currentColor;
  border-left: 0;
  border-radius: 0 2px 2px 0;
  content: "";
}

.section-heading.compact {
  align-items: center;
}

.event-count {
  color: #69746f;
  font-size: 12px;
}

.history-list {
  border-top: 1px solid #d5dcd9;
}

.history-item {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  min-height: 72px;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid #d5dcd9;
}

.history-event-icon {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 6px;
  background: #e1ebe5;
  color: #306e4e;
  font-size: 12px;
  font-weight: 750;
}

.history-event-icon.drinking {
  background: #e2eaed;
  color: #416f80;
}

.history-empty {
  min-height: 86px;
  margin: 0;
  padding: 30px 0;
  border-bottom: 1px solid #d5dcd9;
  color: #7a8580;
  font-size: 13px;
  text-align: center;
}

.history-copy {
  min-width: 0;
}

.history-copy strong,
.history-copy span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-copy strong {
  font-size: 14px;
  line-height: 1.4;
}

.history-copy span {
  margin-top: 3px;
  color: #727c78;
  font-size: 12px;
  line-height: 1.4;
}

.history-pet {
  color: #68736f;
  font-size: 12px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: max(24px, env(safe-area-inset-bottom));
  left: 20px;
  z-index: 10;
  max-width: 480px;
  min-height: 40px;
  margin: 0 auto;
  padding: 10px 14px;
  border-radius: 7px;
  background: #17201d;
  color: #ffffff;
  font-size: 13px;
  line-height: 1.5;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

@media (min-width: 760px) {
  .app-shell {
    padding-top: 28px;
    padding-bottom: 48px;
  }
}

@media (max-width: 360px) {
  .app-shell {
    padding-right: 14px;
    padding-left: 14px;
  }

  .device-state {
    padding-right: 8px;
    padding-left: 8px;
  }

  .care-metric {
    grid-template-columns: 32px minmax(0, 1fr);
    gap: 8px;
    padding-right: 8px;
    padding-left: 8px;
  }

  .care-icon {
    width: 32px;
    height: 32px;
  }

  .care-metric strong {
    font-size: 23px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
  }
}

/* Registered pets and profile navigation. */
[hidden] { display: none !important; }
.pet-nav { display: flex; gap: 8px; margin: 0 0 22px; }
.pet-nav a { flex: 1; text-align: center; padding: 11px; border-radius: 8px; color: #52645b; text-decoration: none; }
.pet-nav a.active { color: #fff; background: #286548; }
.pet-section { margin-bottom: 24px; }
.muted { color: #617369; font-size: 13px; line-height: 1.65; margin: 10px 0 16px; }
.secondary-button, .text-button { cursor: pointer; border: 1px solid #bdd0c3; background: #fff; border-radius: 7px; padding: 9px 12px; color: #28573f; font-size: 13px; }
.text-button { border: 0; background: transparent; }
button:disabled { cursor: not-allowed; opacity: .55; }
.pet-cards { display: grid; gap: 10px; }
.pet-card { display: flex; align-items: center; gap: 13px; padding: 14px; background: #fff; border: 1px solid #d4dfd7; border-radius: 12px; color: inherit; text-decoration: none; }
.pet-card:hover { border-color: #43815b; }
.pet-card img, .pet-portrait { width: 64px; height: 64px; border-radius: 16px; object-fit: cover; background: #e6eee8; }
.pet-card-copy { flex: 1; min-width: 0; }
.pet-card-copy strong, .pet-card-copy small { display: block; overflow-wrap: anywhere; }
.pet-card-copy small { color: #65786c; margin-top: 5px; line-height: 1.5; }
.pet-card-arrow { color: #6c8374; font-size: 22px; }
.pet-slot { padding: 17px; border: 1px dashed #a7bfae; border-radius: 12px; color: #677f6c; font-size: 13px; }
.pet-detail-heading { display: flex; align-items: center; gap: 15px; margin: 15px 0; }
.pet-detail-heading h2 { font-size: 24px; overflow-wrap: anywhere; }
.pet-detail-heading .pet-portrait { width: 88px; height: 88px; }
.summary-scope { margin: 20px 0 10px; font-size: 13px; color: #53695b; }
.pet-dialog { width: min(94vw, 510px); max-height: 92vh; border: 1px solid #d2ddd5; border-radius: 16px; padding: 22px; color: #18211e; background: #f8fbf9; }
.pet-dialog::backdrop { background: rgb(17 35 24 / 48%); }
.pet-dialog label { display: block; margin: 14px 0; font-size: 14px; }
.pet-dialog input, .pet-dialog select { display: block; width: 100%; border: 1px solid #b8cabc; border-radius: 7px; padding: 11px; margin-top: 6px; background: white; color: #18211e; font: inherit; }
.form-pair { display: grid; grid-template-columns: 80px 1fr; gap: 12px; }
.form-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.form-error { color: #9c322b; font-size: 13px; line-height: 1.6; }
.photo-previews { display: flex; flex-wrap: wrap; gap: 9px; margin: 10px 0; }
.photo-previews img { width: 68px; height: 68px; border-radius: 8px; object-fit: cover; }
.photo-previews button { padding: 3px; border: 1px solid #bacabc; border-radius: 9px; background: white; font-size: 11px; color: #77503b; }
.photo-previews button span { display: block; }
#faceCropCanvas { max-width: 100%; touch-action: none; cursor: crosshair; border-radius: 7px; }
.pet-dialog .primary-button { width: 100%; }

.demo-panel { margin: 14px 0; padding: 16px; border: 1px solid #cbd4ce; border-radius: 16px; background: #f7faf8; }
.demo-panel.enabled { border-color: #ba7e21; background: #fff8e8; }
.demo-panel p { margin: 10px 0; font-size: 13px; line-height: 1.6; }
.demo-panel .control-row { gap: 12px; flex-wrap: wrap; }
#demoLiveStatus { font-weight: 600; }
