:root {
  --bg: #1a2e1a;
  --surface: #243824;
  --surface2: #2d4a2d;
  --accent: #5cb85c;
  --accent-dark: #3d8b3d;
  --text: #e8f5e9;
  --text-muted: #a5c8a5;
  --danger: #e57373;
  --radius: 12px;
  --safe-top: env(safe-area-inset-top);
  --safe-bottom: env(safe-area-inset-bottom);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, 'Hiragino Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  padding-top: calc(var(--safe-top) + 56px);
  padding-bottom: calc(var(--safe-bottom) + 16px);
}

/* ヘッダー */
header {
  position: fixed;
  top: var(--safe-top);
  left: 0; right: 0;
  height: 56px;
  background: var(--surface);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 8px;
  z-index: 100;
  border-bottom: 1px solid var(--surface2);
}
header h1 { font-size: 17px; font-weight: 600; flex: 1; }
header .back-btn {
  background: none; border: none; color: var(--accent);
  font-size: 17px; cursor: pointer; padding: 8px 0;
  display: none;
}
header .skip-btn {
  background: none; border: none; color: var(--text-muted);
  font-size: 15px; cursor: pointer; padding: 8px 0;
}

/* ゾーングループ */
.zone-group { margin: 16px 0; }
.zone-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
  letter-spacing: 0.05em;
  padding: 0 16px 8px;
  text-transform: uppercase;
}

/* 植物グリッド */
.plant-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 0 12px;
}

.plant-card {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.plant-card:active { border-color: var(--accent); opacity: 0.85; }

.plant-thumb {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  background: var(--surface2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
}
.plant-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

.plant-name {
  font-size: 11px;
  padding: 6px 6px 8px;
  line-height: 1.3;
  color: var(--text);
  word-break: break-all;
}

/* 撮影画面・確認画面 */
.screen {
  padding: 16px;
  display: none;
}
.screen.active { display: block; }

.selected-plant-info {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 16px;
}
.selected-plant-info img {
  width: 52px; height: 52px;
  border-radius: 8px; object-fit: cover;
  background: var(--surface2);
}
.selected-plant-info .emoji-thumb {
  width: 52px; height: 52px;
  border-radius: 8px;
  background: var(--surface2);
  display: flex; align-items: center; justify-content: center;
  font-size: 28px;
}
.selected-plant-info .plant-title { font-size: 15px; font-weight: 600; }

.photo-area {
  background: var(--surface);
  border-radius: var(--radius);
  aspect-ratio: 4/3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  cursor: pointer;
  margin-bottom: 16px;
  overflow: hidden;
  position: relative;
}
.photo-area img {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
}
.photo-area .icon { font-size: 40px; }
.photo-area .hint { color: var(--text-muted); font-size: 14px; }

textarea {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  padding: 12px;
  min-height: 80px;
  resize: none;
  margin-bottom: 16px;
  outline: none;
}
textarea:focus { border-color: var(--accent); }
textarea::placeholder { color: var(--text-muted); }

.btn {
  display: block;
  width: 100%;
  padding: 16px;
  border-radius: var(--radius);
  border: none;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 10px;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:disabled { background: var(--surface2); color: var(--text-muted); }
.btn-secondary { background: var(--surface); color: var(--text); }

/* 確認画面のプレビュー */
.confirm-photo {
  width: 100%;
  border-radius: var(--radius);
  object-fit: cover;
  max-height: 220px;
  margin-bottom: 12px;
}
.confirm-row {
  display: flex; gap: 8px;
  font-size: 14px; margin-bottom: 8px;
  background: var(--surface);
  border-radius: 8px;
  padding: 10px 12px;
}
.confirm-row .label { color: var(--text-muted); min-width: 52px; }

/* ローディング・エラー */
.spinner {
  display: none;
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
  font-size: 14px;
}
.error-box {
  display: none;
  background: #3a1a1a;
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  padding: 12px;
  color: var(--danger);
  font-size: 14px;
  margin-bottom: 12px;
}
.warning-box {
  background: #3a2a00;
  border: 1px solid #f0a500;
  border-radius: var(--radius);
  padding: 12px;
  color: #f0c050;
  font-size: 13px;
  margin-bottom: 12px;
}

/* 完了画面 */
.done-screen {
  text-align: center;
  padding: 40px 16px;
}
.done-screen .check { font-size: 64px; margin-bottom: 16px; }
.done-screen h2 { font-size: 20px; margin-bottom: 8px; }
.done-screen p { color: var(--text-muted); font-size: 14px; margin-bottom: 24px; }

/* 写真選択画面 */
.screen { padding: 16px; display: none; }
.screen.active { display: block; }
.screen-desc { color: var(--text-muted); font-size: 14px; margin-bottom: 16px; }

.photo-drop-area {
  background: var(--surface);
  border-radius: var(--radius);
  aspect-ratio: 4/3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  cursor: pointer;
  margin-bottom: 16px;
}
.photo-drop-area .icon { font-size: 40px; }
.photo-drop-area .hint { color: var(--text-muted); font-size: 14px; }

.photo-preview-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}
.preview-thumb {
  width: 72px; height: 72px;
  object-fit: cover;
  border-radius: 8px;
  background: var(--surface2);
}

/* 紐付け画面 */
.assign-screen {
  display: none;
  flex-direction: column;
  padding: 0;
  height: calc(100dvh - 56px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  overflow: hidden;
}
.assign-screen.active { display: flex; }

.assign-fixed {
  flex-shrink: 0;
  padding: 8px 16px 0;
}
.assign-progress {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.assign-photo-wrap {
  width: 100%;
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 8px;
  background: var(--surface);
}
.assign-photo-wrap img {
  width: 100%;
  max-height: 200px;
  object-fit: cover;
  display: block;
}
.assign-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 16px;
  -webkit-overflow-scrolling: touch;
}
.assign-new-wrap {
  flex-shrink: 0;
  padding: 8px 16px calc(env(safe-area-inset-bottom) + 8px);
  background: var(--bg);
  border-top: 1px solid var(--surface2);
}
.assign-question {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 12px;
}

.plant-select-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
  max-height: 40vh;
  overflow-y: auto;
}
.plant-select-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 2px solid transparent;
  border-radius: var(--radius);
  padding: 10px 12px;
  color: var(--text);
  font-size: 15px;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s;
}
.plant-select-btn:active { border-color: var(--accent); }
.plant-select-btn img {
  width: 40px; height: 40px;
  border-radius: 6px;
  object-fit: cover;
  background: var(--surface2);
}
.emoji-sm { font-size: 24px; }

/* モーダル */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 24px;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 400px;
}
.modal h3 { font-size: 17px; margin-bottom: 16px; }
.text-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--surface2);
  border-radius: 8px;
  color: var(--text);
  font-size: 15px;
  padding: 12px;
  margin-bottom: 10px;
  outline: none;
  font-family: inherit;
}
.text-input:focus { border-color: var(--accent); }

/* チャット画面 */
.chat-plant-info {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.chat-plant-info img {
  width: 36px; height: 36px;
  border-radius: 6px; object-fit: cover;
}
.plant-title { font-size: 15px; font-weight: 600; }

.chat-photo-wrap {
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 12px;
  background: var(--surface);
  max-height: 200px;
}
.chat-photo-wrap img {
  width: 100%;
  max-height: 200px;
  object-fit: cover;
  display: block;
}

.chat-messages {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px;
  min-height: 80px;
  max-height: 30vh;
  overflow-y: auto;
  margin-bottom: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.chat-bubble {
  max-width: 85%;
  padding: 10px 13px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
}
.chat-bubble.user {
  background: var(--accent-dark);
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}
.chat-bubble.assistant {
  background: var(--surface2);
  color: var(--text);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

.chat-input-wrap {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}
.chat-input-wrap textarea {
  flex: 1;
  margin-bottom: 0;
  min-height: 44px;
  font-size: 14px;
}
.btn-send {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 0 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.btn-send:disabled { background: var(--surface2); color: var(--text-muted); }

.chat-sticky-footer {
  position: sticky;
  bottom: 0;
  background: var(--bg);
  padding: 10px 0 4px;
  margin-top: 10px;
}

/* 日記画面 */
.diary-plant-info { font-size: 14px; color: var(--text-muted); margin-bottom: 10px; }
.diary-photo {
  width: 100%;
  border-radius: var(--radius);
  object-fit: cover;
  max-height: 160px;
  margin-bottom: 12px;
}
.diary-label { font-size: 13px; color: var(--text-muted); margin-bottom: 6px; }
