:root {
  --bg: #f7f2ec;
  --surface: #ffffff;
  --text: #2b1d14;
  --muted: #7d6a5c;
  --line: #e6dbd0;
  --accent: #8a4b2a;
  --accent-text: #ffffff;
  --accent-soft: #f1e3d6;
  --danger: #b3261e;
  --star: #c98a1b;
  --bar: #3b2418;
  --bar-text: #f7f2ec;
  --radius: 12px;
  --tabbar-h: 56px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17110d;
    --surface: #221913;
    --text: #f2e9e1;
    --muted: #a8968a;
    --line: #3a2c22;
    --accent: #d08a5c;
    --accent-text: #1a110b;
    --accent-soft: #3a281c;
    --danger: #f2827a;
    --star: #e8b04a;
    --bar: #0f0a07;
    --bar-text: #f2e9e1;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

a { color: var(--accent); }

/* ---------- バー ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 8px) 16px 8px;
  background: var(--bar);
  color: var(--bar-text);
}
.brand { color: inherit; text-decoration: none; font-weight: 700; font-size: 18px; }

.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 1000;
  display: flex;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.tabbar a {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
}
.tabbar a.active { color: var(--accent); }

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px);
}

/* ---------- 汎用 ---------- */

.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.empty { text-align: center; color: var(--muted); padding: 48px 0; }
.title { font-size: 22px; margin: 8px 0 4px; line-height: 1.35; }

.row { display: flex; gap: 8px; align-items: flex-end; }
.row.between { justify-content: space-between; align-items: center; }
.grow { flex: 1; min-width: 0; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.btn-sm { min-height: 34px; padding: 0 12px; font-size: 14px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-danger { color: var(--danger); }
.btn:disabled { opacity: 0.6; }
.topbar .btn-primary { background: var(--bar-text); border-color: var(--bar-text); color: var(--bar); }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin: 14px 0;
}
.panel h2 { font-size: 15px; margin: 0 0 10px; color: var(--muted); }

.actions { display: flex; gap: 10px; margin: 20px 0; }
.actions .btn { flex: 1; }
.actions.sticky {
  position: sticky;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 8px);
  z-index: 900;
  padding: 8px;
  margin: 20px -8px;
  background: var(--bg);
  border-radius: var(--radius);
}

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
  z-index: 2000;
  transform: translate(-50%, 20px);
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--text);
  color: var(--bg);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- フォーム ---------- */

label { display: block; margin: 0 0 12px; font-size: 14px; font-weight: 600; }
.req { color: var(--danger); font-size: 12px; margin-left: 4px; }

input, select, textarea {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 16px; /* iOSで入力時にズームされないよう16px以上 */
  font-weight: 400;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.row > input { margin-top: 0; }
.row > .btn { flex-shrink: 0; }
.row label { margin-bottom: 12px; }

.scale-row { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.scale-label { width: 3em; font-size: 14px; font-weight: 600; flex-shrink: 0; }
.scale { display: flex; gap: 6px; flex: 1; }
.scale button {
  flex: 1;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.scale button.on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.stars-input button { font-size: 20px; }
.stars-input button.on { background: transparent; border-color: var(--star); color: var(--star); }

.photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 10px; }
.photo-grid > p { grid-column: 1 / -1; margin: 0; }
.photo { position: relative; aspect-ratio: 1; }
.photo img { width: 100%; height: 100%; object-fit: cover; border-radius: 8px; display: block; }
.photo-del {
  position: absolute; top: 4px; right: 4px;
  width: 28px; height: 28px;
  border: none; border-radius: 50%;
  background: rgba(0, 0, 0, 0.6); color: #fff;
  font-size: 16px; line-height: 1; cursor: pointer;
}

.map-label { display: flex; justify-content: space-between; align-items: baseline; font-size: 14px; font-weight: 600; margin: 4px 0 6px; }
.search-results { list-style: none; margin: 6px 0; padding: 0; }
.search-results button {
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  margin-bottom: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}

/* ---------- 一覧 ---------- */

.list-tools { display: flex; gap: 8px; }
.list-tools input { flex: 1; min-width: 0; margin: 0; }
.list-tools select { width: auto; margin: 0; }

.cards { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.card {
  display: flex;
  gap: 12px;
  padding: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: inherit;
  text-decoration: none;
}
.thumb { width: 84px; height: 84px; border-radius: 8px; object-fit: cover; flex-shrink: 0; }
.thumb-empty { display: flex; align-items: center; justify-content: center; background: var(--accent-soft); font-size: 30px; }
.card-body { min-width: 0; }
.card-title { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.stars { color: var(--star); letter-spacing: 1px; }
.stars.big { font-size: 22px; margin: 0 0 8px; }

/* ---------- 詳細 ---------- */

.gallery {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  margin: 0 -16px;
  padding: 0 16px;
}
.gallery a { flex: 0 0 85%; scroll-snap-align: center; }
.gallery a:only-child { flex-basis: 100%; }
.gallery img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: var(--radius); display: block; }

.tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 8px; }
.tag { padding: 2px 10px; border-radius: 999px; background: var(--accent-soft); font-size: 13px; }

dl { margin: 0; }
.kv { display: flex; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.kv:last-child { border-bottom: none; }
.kv dt { width: 6.5em; flex-shrink: 0; color: var(--muted); font-size: 14px; }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.taste .kv dt { width: 3.5em; }

.meter { display: inline-flex; gap: 4px; vertical-align: middle; }
.meter i { width: 26px; height: 10px; border-radius: 3px; background: var(--line); }
.meter i.on { background: var(--accent); }

.memo { white-space: pre-wrap; margin: 0; }

/* ---------- 地図 ---------- */

.map { width: 100%; border-radius: var(--radius); border: 1px solid var(--line); z-index: 0; }
.map-full { height: calc(100dvh - 180px); min-height: 320px; }
.map-small { height: 200px; margin-top: 10px; }
.map-picker { height: 280px; margin-top: 6px; }
.popup { display: block; color: inherit; text-decoration: none; min-width: 140px; }
.popup img { width: 100%; height: 90px; object-fit: cover; border-radius: 6px; margin-bottom: 4px; }

/* 写真から自動入力された欄。手で直すと消える */
input.autofilled, select.autofilled { background: var(--accent-soft); border-color: var(--accent); }

/* 写真の読み取り(OCR)中の表示 */
.extract-status { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 4px 0 0; min-height: 1.6em; }
.extract-status.busy {
  color: var(--text);
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: 10px;
  padding: 10px 12px;
  font-weight: 600;
}
.spinner {
  width: 16px; height: 16px; flex-shrink: 0;
  border: 2px solid var(--accent-soft);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.photo.reading img { filter: brightness(0.75); }
.photo .scan {
  position: absolute; left: 0; right: 0; top: 0;
  height: 3px; border-radius: 2px;
  background: var(--accent);
  box-shadow: 0 0 10px 2px var(--accent);
  animation: scan 1.6s ease-in-out infinite alternate;
  pointer-events: none;
}
@keyframes scan { to { top: calc(100% - 3px); } }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2.4s; }
  .photo .scan { animation: none; top: 50%; }
}
