/* Plantia — 散歩道で見つけた小さな自然を、そっと手帳に書き留める
   v0.2.0 試作「ボタニカルレンズ」の画面に合わせた（白い角丸カード・緑の点線の投稿枠・下に図鑑） */
:root {
  --green: #4CAF50;
  --green-dark: #388E3C;
  --green-soft: #E8F5E9;
  --green-line: #B9DDBB;
  --pink: #FF4081;
  --pink-dark: #E91E63;
  --bg: #FAF8F5;
  --paper: #FFFFFF;
  --text: #3E2723;
  --muted: #8D6E63;
  --line: #EFE9E1;
  --disabled: #E4E6EA;
  --disabled-text: #9AA0A6;
  --warn-bg: #FFF4E5;
  --warn-line: #F3D7B0;
  --radius: 16px;
  --shadow: 0 2px 10px rgba(62, 39, 35, 0.06);
  --font: "Noto Sans JP", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 80px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.75;
  min-height: 100vh;
  padding-bottom: 48px;
}
[hidden] { display: none !important; }
button, input, label.btn { font-family: inherit; }
svg { flex: none; }

/* ヘッダー */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 16px;
  background: rgba(250, 248, 245, 0.94);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; min-width: 0; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 50%; background: var(--green);
  display: grid; place-items: center; flex: none;
}
.brand-mark svg { width: 24px; height: 24px; fill: #fff; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.brand-name { font-weight: 700; font-size: 1.25rem; color: var(--text); letter-spacing: .02em; }
.brand-sub { font-size: .62rem; font-weight: 700; color: var(--muted); letter-spacing: .08em; white-space: nowrap; }
.topbar-actions { display: flex; align-items: center; gap: 2px; }
.icon-btn {
  width: 40px; height: 40px; border: 0; border-radius: 50%;
  background: transparent; color: var(--muted); cursor: pointer;
  display: grid; place-items: center;
}
.icon-btn svg { width: 20px; height: 20px; fill: currentColor; }
.icon-btn:hover { background: var(--green-soft); color: var(--green-dark); }
.icon-btn.is-open { color: var(--green); }
.pill-btn {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 40px; padding: 0 16px; margin-left: 4px; border: 0; border-radius: 999px;
  background: var(--green-soft); color: var(--green-dark); font-size: .9rem; font-weight: 700; cursor: pointer;
}
.pill-btn svg { width: 18px; height: 18px; fill: currentColor; }
.pill-btn:hover { background: #D7EED9; }

.wrap { max-width: 1100px; margin: 0 auto; padding: 24px 16px; }

/* 解析カード */
.hero {
  max-width: 720px; margin: 0 auto;
  background: var(--paper); border: 1px solid var(--line); border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 28px 28px 24px; text-align: center;
}
.pill-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 14px; border-radius: 999px;
  background: var(--green-soft); color: var(--green-dark); font-size: .85rem; font-weight: 700;
}
.pill-badge svg { width: 16px; height: 16px; fill: currentColor; }
.hero-title { font-size: 1.6rem; line-height: 1.45; margin: 16px 0 8px; font-weight: 700; }
.hero-lead { color: var(--muted); font-size: .85rem; margin: 0 0 20px; }

.dropzone {
  position: relative; overflow: hidden;
  min-height: 220px; border: 2px dashed var(--green-line); border-radius: 18px;
  background: #FCFDFB; cursor: pointer;
  display: grid; place-items: center;
  transition: background .15s ease, border-color .15s ease;
}
.dropzone:hover, .dropzone.is-over { background: #F3FAF3; border-color: var(--green); }
.dropzone:focus-visible { outline: 3px solid var(--green); outline-offset: 2px; }
.dropzone.has-photo { cursor: default; border-style: solid; border-color: var(--line); background: #F6F4F0; }
.dz-empty { padding: 32px 16px; }
.dz-icon {
  width: 64px; height: 64px; border-radius: 50%; margin: 0 auto 14px;
  background: var(--green-soft); display: grid; place-items: center;
}
.dz-icon svg { width: 30px; height: 30px; fill: var(--green); }
.dz-title { font-weight: 700; margin: 0; }
.dz-sub { font-size: .8rem; color: var(--muted); margin: 2px 0 0; }
.dz-preview { display: block; width: 100%; max-height: 420px; object-fit: contain; }
.dropzone.is-busy .dz-preview { filter: brightness(.55) blur(1px); }
.dz-analyzing {
  position: absolute; inset: 0; color: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 16px;
}
.sway-leaf { width: 64px; height: 64px; fill: #fff; transform-origin: 20% 90%; animation: sway 2.2s ease-in-out infinite; }
.analyzing-text { font-weight: 700; font-size: 1.05rem; margin: 16px 0 2px; text-shadow: 0 1px 4px rgba(0,0,0,.35); }
.analyzing-sub { margin: 0; font-size: .85rem; text-shadow: 0 1px 4px rgba(0,0,0,.35); }
.dz-change { margin: 8px 0 0; text-align: right; }

.btn-analyze {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; min-height: 52px; margin-top: 20px; border: 0; border-radius: 14px;
  background: var(--green); color: #fff; font-size: 1.05rem; font-weight: 700; cursor: pointer;
  transition: background .15s ease;
}
.btn-analyze svg { width: 22px; height: 22px; fill: currentColor; }
.btn-analyze:hover { background: var(--green-dark); }
.btn-analyze[disabled] { background: var(--disabled); color: var(--disabled-text); cursor: not-allowed; }

.link-btn {
  display: inline-flex; align-items: center; gap: 4px;
  min-height: 36px; padding: 0 6px; border: 0; background: transparent;
  color: var(--green-dark); font-size: .85rem; cursor: pointer;
}
.link-btn svg { width: 16px; height: 16px; fill: currentColor; }
.link-btn:hover { text-decoration: underline; }

/* 解析結果（カードの中） */
.result { text-align: left; margin-top: 20px; padding-top: 20px; border-top: 1px solid var(--line); animation: zoomIn .35s ease both; }
.result-label { display: inline-block; font-size: .8rem; font-weight: 700; color: var(--green-dark); background: var(--green-soft); border-radius: 999px; padding: 2px 12px; margin: 0 0 8px; }
.result-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 20px; }
.result .detail-foot { margin-top: 8px; }

/* 図鑑 */
.gallery { margin-top: 40px; }
.gallery-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.gallery-title { display: flex; align-items: center; gap: 8px; font-size: 1.15rem; margin: 0; }
.gallery-title svg { width: 24px; height: 24px; fill: var(--green); }
.gallery-sub { font-size: .8rem; color: var(--muted); margin: 2px 0 0; }
.refresh { color: var(--muted); }

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

.card {
  display: block; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow); text-decoration: none; color: inherit;
  transition: transform .2s ease, box-shadow .2s ease;
  animation: fadeUp .4s ease both;
}
.card:hover { transform: translateY(-3px); box-shadow: 0 6px 18px rgba(62, 39, 35, 0.12); }
.card.is-new { outline: 3px solid var(--green); outline-offset: -3px; }
.card-img { aspect-ratio: 1 / 1; width: 100%; object-fit: cover; display: block; background: var(--green-soft); }
.card-body { padding: 10px 12px 12px; }
.card-name { font-weight: 700; font-size: 1rem; line-height: 1.4; margin: 0; overflow-wrap: anywhere; }
.card-date { font-size: .75rem; color: var(--muted); margin: 2px 0 0; }

.empty { text-align: center; color: var(--muted); padding: 40px 16px; background: var(--paper); border: 1px dashed var(--line); border-radius: var(--radius); }
.more-wrap { text-align: center; margin-top: 20px; }

/* 詳細（図鑑のカードから開く） */
.detail-view { max-width: 760px; margin: 0 auto; padding: 16px; animation: zoomIn .35s ease both; }
.back { display: inline-flex; align-items: center; gap: 4px; min-height: 44px; color: var(--green-dark); text-decoration: none; font-weight: 500; }
.detail-card { background: var(--paper); border: 1px solid var(--line); border-radius: 20px; overflow: hidden; box-shadow: var(--shadow); }
.detail-img { width: 100%; max-height: 70vh; object-fit: cover; display: block; background: var(--green-soft); }
.detail-body { padding: 20px; }
.detail-name { font-size: 1.6rem; line-height: 1.35; margin: 0; }
.detail-sci { font-style: italic; color: var(--muted); margin: 2px 0 0; }
.badges { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 4px; }
.badge { font-size: .8rem; border-radius: 999px; padding: 2px 12px; background: var(--green-soft); color: var(--green-dark); }
.badge.low { background: var(--warn-bg); color: #9A5B00; }
.section { margin-top: 20px; }
.section h3 { display: flex; align-items: center; gap: 6px; font-size: 1.05rem; margin: 0 0 6px; color: var(--green-dark); }
.section p { margin: 0; white-space: pre-wrap; }
.section.caution { background: var(--warn-bg); border: 1px solid var(--warn-line); border-radius: 12px; padding: 14px 16px; }
.section.caution h3 { color: #9A5B00; }
.section.hanakotoba p { color: var(--pink-dark); font-weight: 500; }
.notice { margin-top: 24px; padding-top: 14px; border-top: 1px dashed var(--line); font-size: .8rem; color: var(--muted); }
.detail-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 16px; }
.btn-danger {
  min-height: 44px; padding: 0 18px; border-radius: 999px; cursor: pointer;
  background: transparent; border: 1px solid #E5B8B8; color: #B23B3B; font-size: .9rem;
}
.btn-danger:hover { background: #FDF0F0; }

/* ボタン・ダイアログ */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 0 22px; border-radius: 999px; border: 0;
  background: var(--green); color: #fff; font-size: 1rem; font-weight: 500;
  cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--green-dark); }
.btn[disabled] { background: #BDBDBD; cursor: not-allowed; }
.btn-ghost {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 0 20px; border-radius: 999px; cursor: pointer;
  background: transparent; border: 1px solid var(--line); color: var(--text); font-size: 1rem; text-decoration: none;
}
.btn-ghost:hover { background: var(--green-soft); }

.dlg {
  border: 0; border-radius: 20px; padding: 24px; width: min(420px, calc(100vw - 32px));
  background: var(--paper); color: var(--text); box-shadow: 0 10px 40px rgba(62, 39, 35, 0.2);
}
.dlg::backdrop { background: rgba(62, 39, 35, 0.35); }
.dlg[open] { animation: zoomIn .25s ease both; }
.dlg h2 { margin: 0 0 8px; font-size: 1.2rem; color: var(--green-dark); }
.dlg label { display: block; font-size: .9rem; margin: 12px 0 0; }
.dlg input {
  display: block; width: 100%; margin-top: 4px; min-height: 44px; padding: 8px 12px;
  border: 1px solid var(--line); border-radius: 10px; font-size: 1rem; font-family: inherit; color: var(--text); background: var(--bg);
}
.dlg input:focus { outline: 2px solid var(--green); outline-offset: 1px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; flex-wrap: wrap; }
.hint { font-size: .85rem; color: var(--muted); margin: 0; }
.form-error { color: #B23B3B; font-size: .9rem; margin: 10px 0 0; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: #fff; padding: 12px 18px; border-radius: 12px; z-index: 60;
  width: max-content; max-width: calc(100vw - 32px); font-size: .9rem; animation: fadeUp .25s ease both;
}

@media (max-width: 480px) {
  .hero { padding: 22px 16px 18px; border-radius: 20px; }
  .hero-title { font-size: 1.3rem; }
  .pill-btn span { display: none; }
  .pill-btn { padding: 0 12px; }
}

@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes zoomIn { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: none; } }
@keyframes sway { 0%, 100% { transform: rotate(-12deg) translateY(0); } 50% { transform: rotate(12deg) translateY(-6px); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
}

/* 設置画面 */
body.setup { display: flex; justify-content: center; align-items: flex-start; padding: 40px 16px; }
.setup-box { background: var(--paper); width: 100%; max-width: 560px; padding: 28px; border-radius: 20px; box-shadow: var(--shadow); }
.setup-box h1 { font-size: 1.35rem; margin: 0 0 20px; color: var(--green-dark); }
.setup-box fieldset { border: 1px solid var(--line); border-radius: 12px; margin: 0 0 18px; padding: 12px 16px 4px; }
.setup-box legend { font-weight: 700; padding: 0 6px; }
.setup-box label { display: block; font-size: .9rem; margin-bottom: 12px; }
.setup-box input { display: block; width: 100%; margin-top: 4px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 1rem; }
.setup-box .hint { margin: 0 0 12px; }
.setup-box .errors { background: #FDF0F0; color: #B23B3B; border: 1px solid #E5B8B8; border-radius: 8px; padding: 10px 10px 10px 28px; font-size: .9rem; }
.setup-box .ok { color: var(--green-dark); font-weight: 700; }
.setup-box code { background: var(--bg); padding: 1px 4px; border-radius: 3px; }
