:root {
  --bg: #fdf6f0;
  --card: #ffffff;
  --accent: #d97a6c;
  --accent-dark: #b86053;
  --text: #2c2421;
  --muted: #8b7d77;
  --border: #f0e3d8;
  --danger: #c0392b;
  --shadow: 0 2px 8px rgba(0,0,0,0.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

header {
  background: var(--accent);
  color: white;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: var(--shadow);
}
header h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}
header a { color: white; text-decoration: none; }
header .back { font-size: 22px; line-height: 1; }

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 12px 12px 100px;
}

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

.card {
  background: var(--card);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  display: flex;
  gap: 12px;
  text-decoration: none;
  color: inherit;
  transition: transform 0.05s;
}
.card:active { transform: scale(0.98); }
.card .thumb {
  width: 84px;
  height: 84px;
  flex: 0 0 84px;
  border-radius: 8px;
  background: #eee center/cover no-repeat;
  position: relative;
}
.card .thumb.no-image {
  background: #f5ebe1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  color: #d4b8a3;
}
.card .thumb .count {
  position: absolute;
  bottom: 4px;
  right: 4px;
  background: rgba(0,0,0,0.6);
  color: white;
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 10px;
}
.card .body {
  flex: 1;
  min-width: 0;
}
.card .meta {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}
.card .weight {
  font-weight: 700;
  font-size: 18px;
  color: var(--accent-dark);
  margin-bottom: 2px;
}
.card .recorder {
  font-size: 13px;
  color: var(--text);
  margin-bottom: 4px;
}
.card .memo {
  font-size: 13px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.fab {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  font-size: 32px;
  border: none;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  z-index: 5;
}
.fab:active { background: var(--accent-dark); }

.form-card {
  background: var(--card);
  border-radius: 12px;
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 12px;
}
.field { margin-bottom: 18px; }
.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 8px;
}

.recorder-options {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.recorder-options label {
  display: block;
  text-align: center;
  padding: 12px 4px;
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: 10px;
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
  cursor: pointer;
  margin: 0;
}
.recorder-options input { display: none; }
.recorder-options input:checked + span {
  display: block;
  padding: 12px 4px;
  margin: -12px -4px;
  background: var(--accent);
  color: white;
  border-radius: 8px;
}

.weight-control {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.weight-control button {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  background: white;
  color: var(--accent);
  font-size: 22px;
  font-weight: 700;
  cursor: pointer;
  flex: 0 0 48px;
}
.weight-control button:active { background: var(--accent); color: white; }
.weight-control input {
  width: 100px;
  text-align: center;
  font-size: 28px;
  font-weight: 700;
  border: none;
  border-bottom: 2px solid var(--border);
  background: transparent;
  color: var(--accent-dark);
  padding: 4px;
}
.weight-control .unit {
  font-size: 16px;
  color: var(--muted);
  margin-left: 4px;
}
.weight-hint {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  margin-top: 8px;
}

textarea, input[type=text], input[type=datetime-local] {
  width: 100%;
  padding: 10px 12px;
  font-size: 15px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: white;
  color: var(--text);
  font-family: inherit;
  resize: vertical;
}
textarea { min-height: 100px; }
textarea:focus, input:focus { outline: none; border-color: var(--accent); }

.file-input {
  display: block;
  text-align: center;
  padding: 14px;
  background: var(--bg);
  border: 2px dashed var(--border);
  border-radius: 10px;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
}
.file-input input { display: none; }
.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px;
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
  font-size: 15px;
}
.check-row input[type=checkbox] {
  width: 22px;
  height: 22px;
  margin: 0;
  accent-color: var(--accent);
}
.check-row:has(input:checked) {
  background: rgba(217, 122, 108, 0.12);
  border-color: var(--accent);
}

.photo-buttons {
  display: flex;
  gap: 8px;
}
.photo-btn {
  flex: 1;
  font-size: 15px;
  font-weight: 600;
  padding: 16px 8px;
}

.preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 6px;
  margin-top: 10px;
}
.preview-grid img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 6px;
}

.btn {
  display: block;
  width: 100%;
  padding: 14px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  font-family: inherit;
}
.btn:active { background: var(--accent-dark); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.secondary {
  background: white;
  color: var(--accent);
  border: 2px solid var(--accent);
}
.btn.danger {
  background: var(--danger);
}
.btn.small {
  padding: 8px 12px;
  font-size: 13px;
  width: auto;
  display: inline-block;
}

.detail-meta {
  background: var(--card);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.detail-meta .row { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.detail-meta .label { font-size: 12px; color: var(--muted); }
.detail-meta .value { font-size: 16px; font-weight: 600; }
.detail-meta .weight-big { font-size: 28px; color: var(--accent-dark); font-weight: 700; }
.detail-meta .memo {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  white-space: pre-wrap;
  font-size: 14px;
}

.detail-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.detail-actions .btn { flex: 1; }

.gallery {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}
.gallery .photo {
  position: relative;
  aspect-ratio: 1;
  background: var(--card);
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  box-shadow: var(--shadow);
}
.gallery .photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.gallery .photo .cover-badge {
  position: absolute;
  top: 6px;
  left: 6px;
  background: var(--accent);
  color: white;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 6px;
  font-weight: 700;
}
.gallery .photo .photo-actions {
  position: absolute;
  top: 6px;
  right: 6px;
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.15s;
}
.gallery .photo.editing .photo-actions { opacity: 1; }
.gallery .photo .photo-actions button {
  background: rgba(0,0,0,0.7);
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 11px;
  padding: 4px 8px;
  cursor: pointer;
}

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.92);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}
.lightbox.open { display: flex; }
.lightbox img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.lightbox .close {
  position: absolute;
  top: 12px;
  right: 16px;
  color: white;
  font-size: 28px;
  background: none;
  border: none;
  cursor: pointer;
  z-index: 1;
}
.lightbox .nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255,255,255,0.2);
  color: white;
  border: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  font-size: 22px;
  cursor: pointer;
}
.lightbox .nav.prev { left: 12px; }
.lightbox .nav.next { right: 12px; }

#camera-overlay {
  position: fixed;
  inset: 0;
  background: black;
  z-index: 300;
  display: none;
  flex-direction: column;
}
#camera-overlay.open { display: flex; }
#camera-overlay .cam-banner {
  position: absolute;
  top: 0; left: 0; right: 0;
  padding: 12px;
  color: white;
  font-size: 12px;
  text-align: center;
  background: rgba(0,0,0,0.6);
  z-index: 1;
}
#camera-overlay video {
  flex: 1;
  width: 100%;
  object-fit: cover;
  background: black;
}
#camera-overlay .cam-controls {
  display: flex;
  gap: 12px;
  padding: 16px env(safe-area-inset-right, 16px) calc(env(safe-area-inset-bottom, 16px) + 16px) env(safe-area-inset-left, 16px);
  background: black;
}
#camera-overlay .cam-controls button {
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 700;
  padding: 16px;
  cursor: pointer;
  font-family: inherit;
}
#camera-overlay #cam-close { flex: 1; background: #333; color: white; }
#camera-overlay #cam-shoot { flex: 2; background: var(--accent); color: white; font-size: 18px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 30px;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.85);
  color: white;
  padding: 10px 20px;
  border-radius: 24px;
  font-size: 14px;
  opacity: 0;
  transition: opacity 0.2s;
  z-index: 200;
  pointer-events: none;
}
.toast.show { opacity: 1; }

.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,0.4);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }
