* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #ffffff;
  --text: #1a1a1a;
  --muted: #666666;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --border: #e5e7eb;
  --success: #16a34a;
  --danger: #dc2626;
  --radius: 12px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

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

header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

header h1 {
  font-size: 18px;
  font-weight: 600;
}

.counter-bar {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

.counter-bar .counter.event.hidden { display: none; }
.counter-bar .dot { color: var(--border); }

.capture-bar {
  display: flex;
  gap: 8px;
  padding: 12px 16px 0;
  align-items: stretch;
}

.event-banner {
  position: relative;
  flex: 1;
  padding: 14px 16px;
  background: #f0f7ff;
  border: 1px solid #bfdbfe;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s;
  /* --banner-accent set inline by renderEventBanner from the chosen
     calendar's backgroundColor; no-op when unset. */
  border-left: 4px solid var(--banner-accent, transparent);
}

.event-banner:hover { background: #e0efff; }

.event-banner .label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 4px;
}

.event-banner .name {
  font-size: 16px;
  font-weight: 600;
  color: var(--accent);
}

.event-banner.inactive {
  background: #f9fafb;
  border-color: var(--border);
}

.event-banner.inactive .name {
  color: var(--muted);
  font-weight: 400;
}

.event-banner.editing {
  background: #f0f7ff;
  border-color: var(--accent);
}

.event-name-input {
  width: 100%;
  padding: 4px 0;
  border: none;
  background: transparent;
  font-size: 16px;
  font-weight: 600;
  color: var(--accent);
  font-family: inherit;
}

.event-name-input:focus { outline: none; }
.event-name-input::placeholder { color: var(--muted); font-weight: 400; }

main {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* --- Photo section --- */

.photo-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.photo-grid:empty { display: none; }

.photo-tile {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.tile-image {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--border);
}

.tile-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.tile-type-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  text-align: center;
  background: none;
  border: none;
  padding: 4px 6px;
  font-family: inherit;
  cursor: pointer;
  user-select: none;
  border-radius: 6px;
  transition: background 0.15s;
}

.tile-type-label:hover { background: #f3f4f6; }
.tile-type-label:active { background: #e5e7eb; }

.photo-tile.type-photo  .tile-type-label { color: #475569; }
.photo-tile.type-person .tile-type-label { color: #16a34a; }
.photo-tile.type-slide  .tile-type-label { color: #2563eb; }

.tile-name-input {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 6px;
  font-size: 12px;
  font-family: inherit;
  width: 100%;
  background: var(--bg);
}

.tile-name-input:focus { outline: none; border-color: var(--accent); }

.tile-image .tile-remove {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(0,0,0,0.65);
  color: white;
  border: none;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.add-photo-btn {
  width: 64px;
  flex-shrink: 0;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--muted);
  transition: border-color 0.15s, color 0.15s;
}

.add-photo-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.add-photo-btn .add-icon { font-size: 32px; line-height: 1; }

/* --- Type selector --- */

.type-selector {
  display: flex;
  gap: 8px;
}

.type-btn {
  flex: 1;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
  transition: all 0.15s;
  color: var(--text);
}

.type-btn:hover { border-color: var(--accent); }
.type-btn.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

/* --- Note block --- */

.note-block {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.note-input {
  width: 100%;
  padding: 12px;
  padding-right: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 16px;
  font-family: inherit;
  resize: vertical;
  min-height: 60px;
}

.note-input:focus { outline: none; border-color: var(--accent); }

.note-toolbar {
  display: flex;
  gap: 6px;
}

.insert-tag-btn {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  color: var(--muted);
  cursor: pointer;
  line-height: 1;
}

.insert-tag-btn:hover { border-color: var(--accent); color: var(--accent); }
.insert-tag-btn:active { background: var(--accent); color: white; border-color: var(--accent); }

/* --- Footer / send --- */

footer {
  padding: 16px;
  padding-bottom: calc(16px + var(--safe-bottom));
  border-top: 1px solid var(--border);
}

.send-btn {
  width: 100%;
  padding: 16px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.send-btn:hover { background: var(--accent-hover); }
.send-btn:disabled { background: #93c5fd; cursor: not-allowed; }
.send-btn.success { background: var(--success); }

.status-bar {
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  margin-top: 8px;
  min-height: 20px;
}

input[type="file"] { display: none; }

/* --- Banner gear (change-calendar affordance) --- */

.banner-gear {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: transparent;
  border: none;
  font-size: 14px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  font-family: inherit;
  transition: background 0.15s, color 0.15s;
}

.banner-gear:hover {
  background: rgba(0, 0, 0, 0.05);
  color: var(--text);
}

.overlap-badge {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  background: rgba(0, 0, 0, 0.06);
  border-radius: 999px;
  vertical-align: middle;
}

/* --- Picker modal (calendar selection, overlap selection) --- */

.picker-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
  padding-bottom: calc(16px + var(--safe-bottom));
  animation: picker-fade-in 0.15s ease-out;
}

@keyframes picker-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.picker-card {
  background: var(--bg);
  border-radius: var(--radius);
  width: 100%;
  max-width: 420px;
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.2);
}

.picker-title {
  padding: 16px 16px 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.picker-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.picker-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: transparent;
  border: none;
  border-radius: 8px;
  font-family: inherit;
  font-size: 16px;
  text-align: left;
  cursor: pointer;
  color: var(--text);
  width: 100%;
  transition: background 0.1s;
}

.picker-item:hover { background: #f3f4f6; }
.picker-item:active { background: #e5e7eb; }
.picker-item.selected { background: #eff6ff; font-weight: 600; }

.picker-color {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  flex-shrink: 0;
  background: var(--border);
}

.picker-label { flex: 1; }

.picker-sublabel {
  font-size: 12px;
  color: var(--muted);
  font-weight: 400;
}

.picker-empty {
  padding: 16px;
  color: var(--muted);
  text-align: center;
  font-size: 14px;
}

.picker-cancel {
  padding: 14px;
  border: none;
  border-top: 1px solid var(--border);
  background: var(--bg);
  font-family: inherit;
  font-size: 16px;
  color: var(--muted);
  cursor: pointer;
}

.picker-cancel:hover { background: #f9fafb; color: var(--text); }
