* { box-sizing: border-box; }
:root {
  --bg: #fff5f7;
  --card: #ffffff;
  --pink: #ff4e7a;
  --pink-dark: #d6325b;
  --text: #2b2b2b;
  --muted: #888;
  --border: #ffd6df;
  --angry: #ff3b30;
  --happy: #34c759;
  --happy-dark: #248a3d;
}
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh;
}
header {
  text-align: center;
  padding: 24px 16px 8px;
}
header h1 {
  margin: 0;
  font-size: 28px;
  color: var(--pink-dark);
}
.subtitle {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
}
main {
  max-width: 760px;
  margin: 0 auto;
  padding: 16px;
}
section {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: 0 4px 16px rgba(255, 78, 122, 0.06);
}
.video-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
}
#video, #overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
#overlay { pointer-events: none; }
.status {
  position: absolute;
  bottom: 8px;
  left: 8px;
  right: 8px;
  background: rgba(0,0,0,0.55);
  color: #fff;
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 8px;
  text-align: center;
}
.emotion-badge {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  color: #fff;
  font-weight: 700;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 14px;
  animation: pulse 0.6s infinite alternate;
}
.emotion-badge.angry {
  background: var(--angry);
  box-shadow: 0 4px 12px rgba(255,59,48,0.5);
}
.emotion-badge.happy {
  background: var(--happy);
  box-shadow: 0 4px 12px rgba(52,199,89,0.5);
}
.rec-badge {
  position: absolute;
  top: 12px;
  right: 12px;
  background: rgba(0,0,0,0.7);
  color: #ff3b30;
  font-weight: 700;
  font-size: 13px;
  padding: 4px 10px;
  border-radius: 999px;
  letter-spacing: 0.5px;
}
.rec-badge::before {
  content: '';
  display: inline-block;
  width: 8px; height: 8px;
  background: #ff3b30;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
  animation: blink 1s infinite;
}
@keyframes blink { 50% { opacity: 0.2; } }
.hidden { display: none !important; }
@keyframes pulse {
  from { transform: translateX(-50%) scale(1); }
  to { transform: translateX(-50%) scale(1.08); }
}
.threshold.checkbox {
  cursor: pointer;
  user-select: none;
}
.threshold.checkbox input { width: auto; margin-right: 4px; }

.live-emotion {
  position: absolute;
  top: 12px;
  left: 12px;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  letter-spacing: 0.3px;
  transition: background 0.2s;
}
.live-emotion.angry { background: rgba(255, 59, 48, 0.92); box-shadow: 0 2px 10px rgba(255,59,48,0.5); }
.live-emotion.happy { background: rgba(52, 199, 89, 0.92); box-shadow: 0 2px 10px rgba(52,199,89,0.5); }

.main-controls {
  justify-content: center;
  margin-top: 14px;
}
button.big {
  font-size: 16px;
  padding: 10px 18px;
  min-width: 56px;
}
button.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
  font-size: 13px;
  padding: 6px 10px;
}
button.ghost:hover:not(:disabled) { background: #fff0f3; }

.settings {
  margin-top: 8px;
  border-top: 1px dashed var(--border);
  padding-top: 8px;
}
.settings[open] { animation: fadein 0.15s ease; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
.settings summary { display: none; }


.controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 8px;
}
button {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 16px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text);
}
button:hover:not(:disabled) { background: #fff0f3; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.primary {
  background: var(--pink);
  color: #fff;
  border-color: var(--pink);
}
button.primary:hover:not(:disabled) { background: var(--pink-dark); }
button.danger {
  color: #b30000;
  border-color: #ffc4c4;
}
button.danger:hover { background: #fff0f0; }

.threshold {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}
.threshold input { width: 110px; }

.records-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  flex-wrap: wrap;
  gap: 8px;
}
.records-header h2 {
  margin: 0;
  font-size: 18px;
  color: var(--pink-dark);
}
.tabs {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}
.tab {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
}
.tab.active {
  background: var(--pink);
  color: #fff;
  border-color: var(--pink);
}
.tab.active .count { background: #fff; color: var(--pink); }
.record.face { aspect-ratio: 1 / 1; }
.emotion-chip {
  position: absolute;
  top: 6px;
  left: 6px;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  letter-spacing: 0.3px;
  pointer-events: none;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}
.emotion-chip.angry-low { background: rgba(255, 152, 0, 0.85); }
.emotion-chip.angry-mid { background: rgba(255, 87, 34, 0.9); }
.emotion-chip.angry-high { background: rgba(255, 59, 48, 0.95); }
.emotion-chip.happy-low { background: rgba(76, 175, 80, 0.85); }
.emotion-chip.happy-mid { background: rgba(46, 160, 67, 0.9); }
.emotion-chip.happy-high { background: rgba(52, 199, 89, 0.95); }
.emotion-chip.none { background: rgba(120, 120, 120, 0.75); font-weight: 400; }

.record.face img { cursor: zoom-in; }

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  cursor: zoom-out;
  padding: 20px;
}
.lightbox img {
  max-width: 100%;
  max-height: 90vh;
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
}
.lb-tip {
  position: absolute;
  bottom: 20px;
  left: 0; right: 0;
  text-align: center;
  color: rgba(255, 255, 255, 0.7);
  font-size: 12px;
  pointer-events: none;
}
.count {
  display: inline-block;
  background: var(--pink);
  color: #fff;
  font-size: 12px;
  border-radius: 999px;
  padding: 2px 10px;
  margin-left: 6px;
}
.records {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}
.record {
  position: relative;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #000;
  aspect-ratio: 4 / 3;
}
.record img,
.record video { width: 100%; height: 100%; object-fit: cover; display: block; background: #000; }
.record .info {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  background: linear-gradient(to top, rgba(0,0,0,0.75), transparent);
  color: #fff;
  font-size: 11px;
  padding: 18px 8px 6px;
  display: flex;
  justify-content: space-between;
}
.record .del {
  position: absolute;
  top: 4px; right: 4px;
  background: rgba(0,0,0,0.55);
  color: #fff;
  border: none;
  border-radius: 999px;
  width: 22px; height: 22px;
  font-size: 12px;
  cursor: pointer;
  padding: 0;
}
.empty {
  color: var(--muted);
  text-align: center;
  font-size: 13px;
  padding: 12px 0;
}

.pane.hidden, .records.hidden { display: none !important; }

.chart-wrap {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  margin-bottom: 14px;
}
.chart-title {
  font-size: 13px;
  color: var(--pink-dark);
  font-weight: 600;
  margin-bottom: 6px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}
.chart-title .stats {
  font-weight: 400;
  color: var(--muted);
  font-size: 11px;
}
#emotion-chart {
  width: 100%;
  height: 180px;
  display: block;
}

.timeline { display: flex; flex-direction: column; gap: 14px; }
.tl-day {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
}
.tl-day-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
}
.tl-day-label { font-weight: 600; color: var(--pink-dark); font-size: 14px; }
.tl-day-stats { color: var(--muted); font-size: 11px; }
.tl-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  -webkit-overflow-scrolling: touch;
}
.tl-strip::-webkit-scrollbar { height: 6px; }
.tl-strip::-webkit-scrollbar-thumb { background: #ffd6df; border-radius: 3px; }
.tl-item {
  flex: 0 0 84px;
  cursor: zoom-in;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.tl-item img {
  width: 84px;
  height: 84px;
  object-fit: cover;
  border-radius: 8px;
  background: #000;
  display: block;
}
.tl-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 10px;
}
.tl-time { color: var(--muted); }
.tl-pct { font-weight: 700; padding: 1px 5px; border-radius: 4px; color: #fff; }
.tl-pct.angry-low { background: rgba(255, 152, 0, 0.9); }
.tl-pct.angry-mid { background: rgba(255, 87, 34, 0.95); }
.tl-pct.angry-high { background: var(--angry); }
.tl-pct.happy-low { background: rgba(76, 175, 80, 0.9); }
.tl-pct.happy-mid { background: rgba(46, 160, 67, 0.95); }
.tl-pct.happy-high { background: var(--happy); }
.tl-pct.none { background: #aaa; }

footer {
  text-align: center;
  padding: 16px;
  font-size: 12px;
  color: var(--muted);
}
footer a { color: var(--pink-dark); }
