:root {
  color-scheme: dark;
  --bg: #000;
  --fg: #fff;
  --muted: #b3b3b3;
  --card: #161616;
  --line: rgba(255, 255, 255, 0.14);
  --accent: #fff;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

body { position: fixed; inset: 0; }

.view {
  position: absolute;
  inset: 0;
  background: #000;
}

.hidden, [hidden] { display: none !important; }

#video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}

#overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

#shutter {
  position: absolute;
  left: 50%;
  bottom: calc(28px + var(--safe-bottom));
  transform: translateX(-50%);
  width: 76px;
  height: 76px;
  border-radius: 50%;
  border: 4px solid #fff;
  background: #fff;
  box-shadow: 0 0 0 4px rgba(0, 0, 0, 0.35), inset 0 0 0 3px #111;
  padding: 0;
  cursor: pointer;
}

#shutter:disabled { opacity: 0.45; }
#shutter:active { transform: translateX(-50%) scale(0.94); }

.history-btn {
  position: absolute;
  left: calc(20px + var(--safe-left));
  bottom: calc(40px + var(--safe-bottom));
  width: 48px;
  height: 48px;
  border: 0;
  border-radius: 14px;
  background: rgba(20, 20, 20, 0.72);
  color: #fff;
  display: grid;
  place-items: center;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  cursor: pointer;
  padding: 0;
}

.history-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 999px;
  background: #fff;
  color: #000;
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}

.icon-btn {
  position: absolute;
  top: calc(10px + var(--safe-top));
  left: calc(10px + var(--safe-left));
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: rgba(20, 20, 20, 0.72);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  z-index: 2;
  padding: 0;
}

#preview {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

.send-btn, .got-it, .open-camera {
  appearance: none;
  border: 0;
  font: inherit;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
}

.send-btn {
  position: absolute;
  left: 50%;
  bottom: calc(28px + var(--safe-bottom));
  transform: translateX(-50%);
  min-width: 180px;
  height: 52px;
  padding: 0 28px;
  border-radius: 999px;
  background: #fff;
  color: #000;
}

.send-btn:active { transform: translateX(-50%) scale(0.97); }

#view-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(20px + var(--safe-top)) calc(24px + var(--safe-right)) calc(20px + var(--safe-bottom)) calc(24px + var(--safe-left));
}

#view-fallback.hidden { display: none !important; }

.open-camera {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 200px;
  height: 52px;
  padding: 0 28px;
  border-radius: 999px;
  background: #fff;
  color: #000;
  position: relative;
}

.open-camera input {
  position: absolute;
  inset: 0;
  opacity: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

/* First-open Safari guide: markup in index.html (#install-guide), logic in app.js */
.install-guide {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, 0.72);
  padding: calc(24px + var(--safe-top)) calc(20px + var(--safe-right)) calc(24px + var(--safe-bottom)) calc(20px + var(--safe-left));
}

.install-guide.hidden { display: none !important; }

.install-guide-card {
  width: min(420px, 100%);
  background: var(--card);
  border-radius: 22px;
  padding: 28px 22px 22px;
  color: #fff;
}

.install-guide-card h1 {
  margin: 0 0 22px;
  font-size: 22px;
  line-height: 1.25;
  font-weight: 700;
  letter-spacing: -0.02em;
  text-align: center;
}

.install-steps {
  list-style: none;
  margin: 0 0 24px;
  padding: 0;
  display: grid;
  gap: 16px;
}

.install-steps li {
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 12px;
  align-items: center;
  font-size: 16px;
  line-height: 1.35;
  color: #eee;
}

.install-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: #2a2a2a;
  color: #fff;
  display: grid;
  place-items: center;
}

.got-it {
  width: 100%;
  height: 52px;
  border-radius: 14px;
  background: #fff;
  color: #000;
}

.got-it:active { transform: scale(0.98); }

.history-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: calc(56px + var(--safe-top));
  padding: var(--safe-top) var(--safe-right) 0 var(--safe-left);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
}

.history-header h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 650;
}

.history-header .icon-btn { position: absolute; }

.history-list {
  position: absolute;
  inset: calc(56px + var(--safe-top)) 0 0 0;
  margin: 0;
  padding: 8px calc(12px + var(--safe-right)) calc(16px + var(--safe-bottom)) calc(12px + var(--safe-left));
  list-style: none;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.history-item {
  display: grid;
  grid-template-columns: 64px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 10px 4px 10px 10px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}

.history-item img {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 8px;
  background: #111;
}

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

.history-meta .name {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-meta .when {
  margin-top: 4px;
  font-size: 13px;
  color: var(--muted);
}

.history-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

.history-actions button {
  width: 44px;
  height: 44px;
  border: 0;
  background: transparent;
  color: #fff;
  display: grid;
  place-items: center;
  padding: 0;
  cursor: pointer;
}

.history-actions .trash { color: #ff7b7b; }

.history-empty {
  position: absolute;
  left: 0;
  right: 0;
  top: 45%;
  text-align: center;
  color: var(--muted);
  font-size: 16px;
}
