:root {
  --bg: #f8f3ee;
  --card: #ffffff;
  --ink: #2b2320;
  --muted: #7d7069;
  --accent: #a4553f;
  --line: #e7ddd5;
  --error: #b3261e;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

main {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 16px) 16px calc(env(safe-area-inset-bottom) + 32px);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

h1 { font-size: 28px; margin: 0; }
h2 { font-size: 20px; margin: 0 0 4px; }
p { margin: 0; }

.top { display: flex; align-items: center; justify-content: space-between; }
.muted { color: var(--muted); }
.empty { text-align: center; padding: 28px 8px; }
.error { color: var(--error); font-size: 15px; }
.error:empty { display: none; }
.center { text-align: center; align-items: center; }

.card {
  background: var(--card);
  border-radius: 16px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login { margin-top: 18vh; }

button, .secondary, input, textarea { font: inherit; }

button { cursor: pointer; color: inherit; }
button:disabled { opacity: .55; }

.primary, .secondary {
  display: block;
  width: 100%;
  min-height: 48px;
  padding: 12px;
  border-radius: 12px;
  text-align: center;
  text-decoration: none;
  font-weight: 600;
}

.primary { border: 0; background: var(--accent); color: #fff; }
.secondary { border: 1px solid var(--line); background: transparent; color: var(--ink); }
.big { min-height: 56px; }

.link {
  border: 0;
  background: none;
  color: var(--accent);
  padding: 8px 0;
  min-height: 44px;
}

.back { align-self: flex-start; }
.danger { color: var(--error); }

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
  color: var(--muted);
}

/* 16px or more stops iPhone from zooming in when a field is tapped. */
input, textarea {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font-size: 17px;
  resize: vertical;
}

.list { display: flex; flex-direction: column; gap: 10px; }

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px;
  border: 0;
  border-radius: 14px;
  background: var(--card);
  text-align: left;
}

.row img { width: 64px; height: 64px; object-fit: cover; border-radius: 10px; flex: none; }
.row-text { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; min-width: 0; }

.pill {
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 13px;
  background: var(--line);
  align-self: flex-start;
}

.pill.ready { background: #f6dfc8; }
.pill.posted { background: #d9ead9; }
.pill.failed { background: #f6d7d4; }

.preview, .gallery img { width: 100%; max-height: 52vh; object-fit: contain; border-radius: 14px; background: #000; }

.gallery { display: flex; gap: 8px; overflow-x: auto; scroll-snap-type: x mandatory; }
.gallery img { flex: 0 0 100%; scroll-snap-align: center; }

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .9s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 4s; }
}

#toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(env(safe-area-inset-bottom) + 20px);
  max-width: 528px;
  margin: 0 auto;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--ink);
  color: #fff;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}

#toast.show { opacity: 1; }

.tags { display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  font-size: 15px;
  overflow-wrap: anywhere;
}

.chip.on { border-color: var(--accent); background: var(--accent); color: #fff; }

.chip-group { display: inline-flex; }
.chip-group .chip:first-child { border-radius: 999px 0 0 999px; border-right: 0; }
.chip-group .star { border-radius: 0 999px 999px 0; color: var(--accent); min-width: 42px; justify-content: center; }

.section { display: flex; flex-direction: column; gap: 8px; }
.section-title { font-size: 14px; color: var(--muted); }
.hint { font-size: 14px; color: var(--muted); }

.inline-form { display: flex; gap: 8px; }
.inline-form input { flex: 1; min-width: 0; }
.inline-form .secondary { width: auto; flex: none; padding: 10px 14px; }

details summary { min-height: 40px; padding: 8px 0; font-weight: 600; cursor: pointer; }
details .tags { padding-bottom: 8px; }

.folder-actions { display: flex; gap: 16px; }

.spinner.small { width: 18px; height: 18px; border-width: 2px; flex: none; }
.working { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 15px; }

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

.photo {
  position: relative;
  aspect-ratio: 1;
  padding: 0;
  border: 3px solid transparent;
  border-radius: 10px;
  overflow: hidden;
  background: var(--line);
}

.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo.selected { border-color: var(--accent); }

.badge:empty { display: none; }

.badge {
  position: absolute;
  top: 6px;
  left: 6px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  line-height: 26px;
  font-weight: 700;
}

.used {
  position: absolute;
  right: 4px;
  bottom: 4px;
  padding: 0 6px;
  border-radius: 999px;
  background: rgba(0, 0, 0, .6);
  color: #fff;
  font-size: 12px;
}

canvas.preview { display: block; height: auto; background: #fff; }
input.range { padding: 0; border: 0; background: none; accent-color: var(--accent); }
.check { flex-direction: row; align-items: center; font-size: 16px; color: var(--ink); }
.check input { width: 22px; height: 22px; flex: none; accent-color: var(--accent); }

.filter-panel { padding: 4px 14px; border-radius: 14px; background: var(--card); }
.filter-panel summary { display: flex; align-items: center; }
.filter-body { display: flex; flex-direction: column; gap: 14px; padding: 6px 0 12px; }
.date-range { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.date-range label { min-width: 0; }
.date-range input { min-width: 0; padding: 10px 8px; font-size: 16px; }
.result-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 28px; }
.photo-grid[hidden], .empty[hidden] { display: none; }
.shades { padding: 8px; border-radius: 12px; background: var(--bg); }
.shades[hidden], .hint:empty { display: none; }
.ai-working { padding: 12px 14px; border-radius: 12px; background: var(--card); color: var(--ink); font-size: 18px; font-weight: 600; }
.ai-working[hidden] { display: none; }
.ai-switch { padding: 12px 14px; border-radius: 14px; background: var(--card); }
.remove-photo { position: absolute; top: 4px; right: 4px; width: 32px; height: 32px; padding: 0; border: 0; border-radius: 50%; background: rgba(0, 0, 0, .6); color: #fff; font-size: 20px; line-height: 32px; }
