:root {
  --green: #2e7d32;
  --green-dark: #1b5e20;
  --leaf: #66bb6a;
  --cream: #f6f3e7;
  --card: #ffffff;
  --ink: #2d2a24;
  --muted: #7a756a;
  --amber: #f4a836;
  --danger: #d84315;
  --shadow: 0 4px 14px rgba(0, 0, 0, 0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--cream);
  color: var(--ink);
  font-family: "Hiragino Maru Gothic ProN", "Yu Gothic", "Meiryo", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body {
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
  min-height: 100vh;
}

.app-header {
  background: linear-gradient(135deg, var(--green) 0%, var(--leaf) 100%);
  color: #fff;
  padding: calc(16px + env(safe-area-inset-top)) 16px 16px;
  text-align: center;
  border-radius: 0 0 22px 22px;
  box-shadow: var(--shadow);
}
.app-header h1 { margin: 0; font-size: 1.6rem; letter-spacing: 1px; }
.tagline { margin: 4px 0 0; font-size: 0.9rem; opacity: 0.95; }

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

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.card {
  background: var(--card);
  border-radius: 18px;
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.card h2 { margin: 0 0 12px; font-size: 1.15rem; color: var(--green-dark); }

/* 写真エリア */
.photo-drop {
  display: block;
  border: 3px dashed var(--leaf);
  border-radius: 16px;
  background: #f1f8f1;
  cursor: pointer;
  overflow: hidden;
  position: relative;
}
.photo-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 180px;
  color: var(--muted);
  text-align: center;
  font-size: 0.95rem;
}
.big-emoji { font-size: 2.8rem; }
.photo-preview { width: 100%; display: block; max-height: 340px; object-fit: contain; background: #000; }

/* コンテキスト */
.context-box { margin: 14px 0; }
.context-box summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--green-dark);
  padding: 8px 0;
}
.field { margin: 10px 0; }
.field label { display: block; font-size: 0.88rem; color: var(--muted); margin-bottom: 4px; }
.field select, .field input[type="text"] {
  width: 100%;
  padding: 11px 12px;
  border: 1.5px solid #dcd7c8;
  border-radius: 12px;
  font-size: 1rem;
  background: #fff;
  font-family: inherit;
}

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1.5px solid #dcd7c8;
  background: #fff;
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 0.9rem;
  cursor: pointer;
  font-family: inherit;
  color: var(--ink);
}
.chip.selected { background: var(--leaf); color: #fff; border-color: var(--leaf); }

.primary-btn {
  width: 100%;
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: 14px;
  padding: 15px;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  box-shadow: var(--shadow);
}
.primary-btn:active { transform: translateY(1px); }
.primary-btn:disabled { opacity: 0.6; }

.ghost-btn {
  background: #eee;
  color: var(--ink);
  border: none;
  border-radius: 14px;
  padding: 13px 16px;
  font-size: 1rem;
  cursor: pointer;
  font-family: inherit;
}

.hint { color: var(--muted); font-size: 0.88rem; margin: 10px 2px 0; text-align: center; }

/* 結果 */
.results { margin-top: 4px; }
.result-summary {
  background: #fff8e8;
  border: 1.5px solid #ffe2a8;
  border-radius: 14px;
  padding: 12px 14px;
  margin-bottom: 12px;
  font-size: 0.95rem;
}
.candidate {
  background: var(--card);
  border-radius: 16px;
  padding: 14px;
  box-shadow: var(--shadow);
  margin-bottom: 12px;
  border-left: 6px solid var(--leaf);
}
.candidate .cand-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.candidate .cand-name { font-size: 1.25rem; font-weight: 800; color: var(--green-dark); }
.candidate .cand-reading { font-size: 0.85rem; color: var(--muted); }
.badge {
  font-size: 0.75rem;
  padding: 2px 9px;
  border-radius: 999px;
  font-weight: 700;
  white-space: nowrap;
}
.badge.kind { background: #e8f5e9; color: var(--green-dark); }
.conf-高 { background: #e6f4ea; color: #1b7a3d; }
.conf-中 { background: #fff3d6; color: #b7791f; }
.conf-低 { background: #fde8e8; color: #c0392b; }
.cand-row { margin-top: 8px; font-size: 0.92rem; line-height: 1.5; }
.cand-row .lab { font-weight: 700; color: var(--green); }
.cand-caution { margin-top: 8px; background: #fdecea; color: var(--danger); border-radius: 10px; padding: 8px 10px; font-size: 0.88rem; }
.cand-save { margin-top: 10px; width: 100%; background: var(--amber); color: #3a2c00; border: none; border-radius: 12px; padding: 11px; font-weight: 700; cursor: pointer; font-family: inherit; }

.spinner {
  width: 34px; height: 34px;
  border: 4px solid #d8ecd8;
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
  margin: 16px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ログ */
.log-list { display: flex; flex-direction: column; gap: 12px; }
.log-item {
  background: var(--card);
  border-radius: 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  gap: 0;
}
.log-thumb { width: 96px; min-width: 96px; height: 96px; object-fit: cover; background: #eee; }
.log-body { padding: 10px 12px; flex: 1; min-width: 0; }
.log-name { font-weight: 800; color: var(--green-dark); font-size: 1.05rem; }
.log-meta { font-size: 0.8rem; color: var(--muted); margin-top: 2px; }
.log-memo { font-size: 0.85rem; margin-top: 4px; }
.log-actions { display: flex; gap: 8px; margin-top: 8px; }
.log-actions button {
  border: none; border-radius: 10px; padding: 7px 12px;
  font-size: 0.85rem; cursor: pointer; font-family: inherit; font-weight: 700;
}
.share-btn { background: #e3f2fd; color: #1565c0; }
.del-btn { background: #f5f5f5; color: #999; }

.empty-state { text-align: center; color: var(--muted); padding: 40px 16px; }
.empty-state .big-emoji { display: block; margin-bottom: 10px; }

/* タブバー */
.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: flex;
  background: #fff;
  border-top: 1px solid #e6e1d3;
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -2px 10px rgba(0,0,0,0.05);
}
.tab-btn {
  flex: 1;
  border: none;
  background: none;
  padding: 10px 0 8px;
  font-size: 1.5rem;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-family: inherit;
}
.tab-btn span { font-size: 0.72rem; }
.tab-btn.active { color: var(--green); }

/* ダイアログ */
.dialog {
  border: none;
  border-radius: 18px;
  padding: 20px;
  width: min(92vw, 420px);
  box-shadow: 0 10px 40px rgba(0,0,0,0.3);
}
.dialog::backdrop { background: rgba(0,0,0,0.4); }
.dialog h3 { margin: 0 0 12px; color: var(--green-dark); }
.checkline { display: flex; align-items: center; gap: 8px; margin: 10px 0; font-size: 0.95rem; }
.dialog-actions { display: flex; gap: 10px; margin-top: 16px; }
.dialog-actions .ghost-btn { flex: 1; }
.dialog-actions .primary-btn { flex: 2; }

.toast {
  position: fixed;
  bottom: 90px; left: 50%;
  transform: translateX(-50%);
  background: rgba(40,40,40,0.92);
  color: #fff;
  padding: 11px 18px;
  border-radius: 999px;
  font-size: 0.9rem;
  z-index: 50;
  animation: fadeup 0.3s ease;
}
@keyframes fadeup { from { opacity: 0; transform: translate(-50%, 8px); } }
