:root {
  --bg: #f4f1e8;
  --bg-card: #ffffff;
  --primary: #1a3a2e;
  --primary-2: #2d5a3f;
  --accent: #c9a961;
  --text: #1f2a23;
  --muted: #6b6b6b;
  --danger: #b3261e;
  --border: #e3decd;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--primary);
  color: white;
  padding: 18px 20px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow);
}
header h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.3px;
}
.count {
  background: var(--accent);
  color: var(--primary);
  font-weight: 700;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 14px;
}

main {
  padding: 16px 16px 120px;
  max-width: 720px;
  margin: 0 auto;
}

#search {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 16px;
  background: white;
  margin-bottom: 16px;
  outline: none;
}
#search:focus { border-color: var(--primary-2); }

.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
@media (min-width: 600px) {
  .grid { grid-template-columns: repeat(3, 1fr); }
}

.card {
  background: var(--bg-card);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.1s;
  display: flex;
  flex-direction: column;
}
.card:active { transform: scale(0.97); }
.card-photo {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  background: #ddd;
  display: block;
}
.card-photo-placeholder {
  width: 100%;
  aspect-ratio: 1 / 1;
  background: linear-gradient(135deg, #d6cdb0, #c9a961);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 42px;
}
.card-body {
  padding: 10px 12px 12px;
}
.card-name {
  font-weight: 700;
  font-size: 15px;
  line-height: 1.2;
  margin-bottom: 2px;
}
.card-meta {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.3;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 60px 20px;
}
.empty p { margin: 6px 0; }

.fab {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--primary);
  color: white;
  border: none;
  padding: 16px 28px;
  border-radius: 999px;
  font-size: 17px;
  font-weight: 700;
  box-shadow: 0 6px 20px rgba(26, 58, 46, 0.35);
  cursor: pointer;
  z-index: 20;
}
.fab:active { transform: translateX(-50%) scale(0.97); }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 30;
  animation: fadeIn 0.15s ease-out;
}
.modal-content {
  background: var(--bg);
  width: 100%;
  max-width: 560px;
  max-height: 92vh;
  overflow-y: auto;
  border-radius: 20px 20px 0 0;
  padding: 18px 18px 28px;
  position: relative;
  animation: slideUp 0.2s ease-out;
}
@media (min-width: 600px) {
  .modal { align-items: center; }
  .modal-content { border-radius: 20px; }
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

.modal h2 {
  margin: 0 0 14px;
  font-size: 20px;
}
.close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: rgba(0, 0, 0, 0.06);
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 16px;
  cursor: pointer;
  color: var(--text);
}

.photo-picker {
  display: block;
  cursor: pointer;
}
.photo-preview-wrap {
  width: 100%;
  aspect-ratio: 1 / 1;
  max-height: 320px;
  background: white;
  border: 2px dashed var(--border);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  margin-bottom: 12px;
  position: relative;
}
.photo-placeholder {
  text-align: center;
  font-size: 18px;
  color: var(--muted);
  line-height: 1.6;
}
#photo-preview {
  display: none;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
#photo-preview.shown { display: block; }
#photo-preview.shown + .photo-placeholder { display: none; }

#fields {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
}
#fields label {
  display: flex;
  flex-direction: column;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  gap: 4px;
}
#fields input,
#fields textarea,
#fields select {
  font-family: inherit;
  font-size: 16px;
  font-weight: 400;
  color: var(--text);
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: white;
  outline: none;
  resize: vertical;
  width: 100%;
}
#fields input:focus,
#fields textarea:focus,
#fields select:focus { border-color: var(--primary-2); }

.input-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}
.input-row input { flex: 1; }
.btn-icon {
  background: var(--accent);
  color: var(--primary);
  border: none;
  width: 44px;
  border-radius: 10px;
  font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
}
.btn-icon:active { transform: scale(0.95); }
.btn-icon:disabled { opacity: 0.5; }

.actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}
.btn-primary {
  flex: 1;
  background: var(--primary);
  color: white;
  border: none;
  padding: 14px;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  width: 100%;
  display: block;
  margin-top: 4px;
}
.btn-primary:active { background: var(--primary-2); }
.btn-primary:disabled { opacity: 0.5; }
.btn-danger {
  background: white;
  color: var(--danger);
  border: 1px solid var(--danger);
  padding: 14px 18px;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.status {
  margin: 8px 0 0;
  font-size: 14px;
  color: var(--muted);
  text-align: center;
}
.status.error { color: var(--danger); }

.hidden { display: none !important; }
