/*
 * TADAIMA — 木漏れ日の道（D案）
 * 継続と成長を描き、AI companion "TADAIMA" の世界観を表現する。
 * 詳細は docs/ 以下の設計ドキュメントと、デザイン検討時のやり取りを参照。
 */

:root {
  --bg-top: #DCEEE9;
  --bg-mid: #F3EFD8;
  --bg-bottom: #F9F2DC;
  --ink: #3C4A34;
  --sub: #7C8A66;
  --sub-light: #8A9A72;
  --card-bg: rgba(255, 253, 246, 0.82);
  --card-bg-soft: rgba(255, 253, 246, 0.7);
  --line: rgba(143, 173, 111, 0.35);
  --line-soft: rgba(143, 173, 111, 0.22);
  --accent: #7C9A5C;
  --accent-dark: #4A6B33;
  --accent-label: #7C9A5C;
  --cream: #FBF9F0;
  --stamp: #C97D60;
}

* { box-sizing: border-box; }

html, body {
  min-height: 100%;
}

html { overflow-x: hidden; }
body {
  margin: 0;
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--ink);
  line-height: 1.65;
  background: linear-gradient(180deg, var(--bg-top) 0%, var(--bg-mid) 55%, var(--bg-bottom) 100%);
  min-height: 100vh;
  overflow-x: hidden;
  overflow-wrap: break-word;
}

.page-shell {
  max-width: 480px;
  margin: 0 auto;
}

.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; }
}

/* ---- フラッシュ ---- */
.flash { margin: 0 20px; padding: 10px 14px; border-radius: 10px; font-size: 13px; }
.flash.notice { background: rgba(124, 154, 92, 0.18); color: var(--accent-dark); }
.flash.alert { background: rgba(201, 125, 96, 0.18); color: var(--stamp); }

/* ============ 画面共通の余白・装飾 ============ */
.app-screen {
  position: relative;
  overflow: hidden;
  padding: 30px 20px 24px;
  min-height: calc(100vh - 20px);
}
body.with-tab-bar .app-screen { padding-bottom: calc(54px + env(safe-area-inset-bottom) + 10px + 24px); }

.dapple {
  position: absolute; border-radius: 50%; pointer-events: none;
  background: radial-gradient(circle, rgba(255, 244, 201, 0.9), rgba(255, 244, 201, 0) 72%);
  filter: blur(1px);
  animation: dapple-drift 9s ease-in-out infinite;
}
.dapple-1 { width: 140px; height: 140px; top: -10px; left: -30px; }
.dapple-2 { width: 100px; height: 100px; top: 60px; right: -20px; animation-delay: 2.4s; }
@keyframes dapple-drift {
  0%, 100% { transform: translateY(0) scale(1); opacity: 0.8; }
  50% { transform: translateY(10px) scale(1.08); opacity: 1; }
}

.greeting {
  position: relative;
  font-family: "Hiragino Maru Gothic ProN", "Hiragino Sans", sans-serif;
  font-size: 26px; font-weight: 700; margin: 4px 0 2px;
}
.page-title {
  position: relative;
  font-family: "Hiragino Maru Gothic ProN", "Hiragino Sans", sans-serif;
  font-size: 22px; font-weight: 700; margin: 4px 0 2px;
}
.subname { position: relative; font-size: 13px; color: var(--sub); margin: 0 0 20px; }

.section { position: relative; margin-bottom: 20px; }
.section-label {
  font-size: 11px; letter-spacing: 0.08em; color: var(--sub); margin: 0 0 10px; font-weight: 700;
}
.empty-note { font-size: 13px; color: var(--sub); }

/* ---- カード ---- */
.card {
  position: relative;
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: 16px; padding: 14px 16px; margin-bottom: 16px;
  box-shadow: 0 8px 20px -12px rgba(80, 100, 60, 0.35);
}
.card-label { font-size: 10.5px; letter-spacing: 0.08em; color: var(--accent-label); margin: 0 0 5px; font-weight: 700; }
.card-value {
  font-family: "Hiragino Maru Gothic ProN", sans-serif;
  font-size: 15px; margin: 0 0 10px; color: var(--ink);
}
.card-value:last-child { margin-bottom: 0; }

.resume-card {
  display: block; position: relative;
  background: var(--card-bg); border: 1px solid var(--line);
  border-radius: 14px; padding: 12px 15px; margin-bottom: 16px;
  font-size: 13px; color: var(--accent-dark); text-decoration: none;
}

/* ---- 最近の挑戦：タップで今日のテーマに切り替え ---- */
.hint-text { font-size: 11px; color: var(--sub-light); margin: 0 0 8px; }
.recent-theme-item {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--card-bg); border: 1px solid var(--line);
  border-radius: 14px; padding: 11px 14px; margin: 0 0 8px;
  font-size: 12.5px; color: var(--ink); text-align: left; font-weight: 400;
}
.recent-theme-text { flex: 1; line-height: 1.4; }
.recent-theme-count {
  flex-shrink: 0; display: flex; align-items: center; gap: 3px;
  font-size: 11px; color: var(--sub); font-variant-numeric: tabular-nums;
}
.mini-icon {
  width: 13px; height: 13px; flex-shrink: 0;
  stroke: var(--accent); fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}

/* ---- 挑戦数カード ---- */
.achieve-card {
  position: relative;
  display: flex; align-items: center; gap: 12px;
  background: var(--card-bg); border: 1px solid var(--line);
  border-radius: 16px; padding: 13px 16px; margin: 16px 0;
}
.achieve-icon {
  width: 28px; height: 28px; flex-shrink: 0;
  stroke: var(--accent); fill: none; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round;
}
.achieve-num {
  font-family: "Hiragino Maru Gothic ProN", sans-serif;
  font-size: 21px; font-weight: 700; color: var(--ink); margin: 0; line-height: 1.1;
}
.achieve-label { font-size: 11.5px; color: var(--sub); margin: 2px 0 0; }

/* ---- ここまでの歩み ---- */
.review-box {
  font-size: 13px; color: var(--ink); background: var(--card-bg-soft);
  border-radius: 14px; padding: 13px 15px; line-height: 1.7;
  border: 1px solid rgba(143, 173, 111, 0.25);
}

/* ---- 最近の記録 ---- */
.date-sep {
  font-size: 10.5px; font-weight: 700; letter-spacing: 0.04em; color: var(--sub-light);
  margin: 14px 0 6px;
}
.date-sep:first-child { margin-top: 0; }
.record-row {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 9px 0; border-bottom: 1px solid var(--line-soft);
  text-decoration: none; color: inherit;
}
.record-icon {
  width: 15px; height: 15px; flex-shrink: 0; margin-bottom: 1px;
  stroke: var(--accent); fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round;
}
.record-text { flex: 1; font-size: 12.5px; color: var(--ink); line-height: 1.4; }
.record-time { font-size: 10.5px; color: var(--sub-light); flex-shrink: 0; font-variant-numeric: tabular-nums; }

/* ---- チップ（のびしろ） ---- */
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  font-size: 12.5px; color: var(--ink);
  background: var(--card-bg); border: 1px solid var(--line);
  border-radius: 999px; padding: 7px 14px;
}

/* ---- チャート ---- */
.chart-wrap {
  background: var(--card-bg-soft); border: 1px solid rgba(143, 173, 111, 0.25);
  border-radius: 14px; padding: 12px;
}
.chart-wrap canvas { max-width: 100%; }
.chart-wrap--wide { padding: 14px 10px; }

/* ---- 課題（バックログ）：左スワイプで操作が出てくるカード ---- */
.swipe-hint { font-size: 11px; color: var(--sub-light); margin: 0 0 8px; }

.backlog-item {
  position: relative;
  border-radius: 14px; margin-bottom: 10px;
  overflow: hidden;
}
.backlog-actions {
  position: absolute; top: 0; bottom: 0; right: 0; width: 96px;
  display: flex; align-items: center; justify-content: flex-end; gap: 8px;
  padding-right: 12px;
}
.backlog-content {
  position: relative;
  /* スワイプで隠れるボタンが透けないよう、不透明な背景にする */
  background: var(--cream); border: 1px solid rgba(143, 173, 111, 0.3);
  border-radius: 14px; padding: 12px 14px;
  touch-action: pan-y;
  transition: transform 0.25s cubic-bezier(0.2, 0.8, 0.3, 1);
  user-select: none;
}
.backlog-content.dragging { transition: none; }
.backlog-content p { font-size: 12.5px; margin: 0; color: var(--ink); line-height: 1.5; }

.challenge-btn, .dismiss-btn {
  width: 34px; height: 34px; flex-shrink: 0;
  border: none; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}
.challenge-btn { background: var(--accent); }
.dismiss-btn { background: var(--stamp); }
.challenge-btn .btn-icon, .dismiss-btn .btn-icon {
  width: 16px; height: 16px; flex-shrink: 0;
  stroke: var(--cream); fill: none; stroke-width: 2.1; stroke-linecap: round; stroke-linejoin: round;
}

.tackled-item {
  font-size: 12.5px; padding: 9px 0; border-bottom: 1px solid var(--line-soft);
  color: var(--ink); display: flex; justify-content: space-between; gap: 8px;
}
.tackled-item .meta { color: var(--sub-light); font-size: 11px; white-space: nowrap; }

/* ---- ホーム／チャット共通の入力エリア ---- */
.chat-input-area {
  position: relative;
  display: flex; align-items: flex-end; gap: 8px;
  margin-bottom: 16px;
}
.chat-input-area--home { margin-top: 4px; }
.attach-btn {
  width: 32px; height: 32px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.attach-btn svg {
  width: 19px; height: 19px;
  stroke: var(--accent); fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round;
}
.chat-textarea {
  flex: 1; min-height: 56px; resize: vertical;
  background: var(--card-bg); border: 1px solid var(--line);
  border-radius: 16px; padding: 9px 13px;
  font-family: inherit; color: var(--ink); line-height: 1.4;
  /* 16px未満だとiOS Safariがフォーカス時に自動拡大してしまうため */
  font-size: 16px;
}
.chat-textarea::placeholder { color: var(--sub-light); white-space: pre-wrap; }
.send-btn {
  width: 34px; height: 34px; flex-shrink: 0; border: none; border-radius: 50%;
  background: var(--accent); display: flex; align-items: center; justify-content: center;
}
.send-btn:disabled { opacity: 0.5; }
.send-btn svg {
  width: 16px; height: 16px; flex-shrink: 0;
  stroke: var(--cream); fill: none; stroke-width: 2.1; stroke-linecap: round; stroke-linejoin: round;
}
.chat-image-preview {
  max-width: 90px; max-height: 90px; border-radius: 10px; margin-bottom: 6px;
}
.chat-image-preview:not([hidden]) { display: block; }

/* ---- チャット画面 ---- */
.chat-page { display: flex; flex-direction: column; min-height: calc(100vh - 20px); }
.chat-header { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.chat-back-link { display: flex; }
.chat-back {
  width: 22px; height: 22px;
  stroke: var(--accent-dark); fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.chat-title {
  font-family: "Hiragino Maru Gothic ProN", sans-serif;
  font-size: 19px; font-weight: 700; color: var(--ink); margin: 0;
}
.chat-theme-strip {
  background: var(--card-bg-soft); border: 1px solid rgba(143, 173, 111, 0.3);
  border-radius: 12px; padding: 9px 13px; font-size: 11.5px; color: var(--sub);
  margin-bottom: 14px;
}
.chat-theme-strip strong { color: var(--ink); font-weight: 700; }

.chat-body { flex: 1; }

.bubble-row { display: flex; margin-bottom: 12px; }
.bubble-row.assistant { justify-content: flex-start; }
.bubble-row.user { justify-content: flex-end; }
.bubble {
  max-width: 80%; padding: 10px 14px; border-radius: 17px;
  font-size: 13px; line-height: 1.65; white-space: pre-wrap;
  overflow-wrap: break-word; word-break: break-word;
}
.bubble.assistant {
  background: var(--card-bg); color: var(--ink); border-bottom-left-radius: 5px;
  box-shadow: 0 4px 12px -8px rgba(80, 100, 60, 0.3);
}
.bubble.user { background: var(--accent); color: var(--cream); border-bottom-right-radius: 5px; }
.bubble-image { display: block; width: 100%; border-radius: 10px; margin-bottom: 6px; }

.typing-row { margin-bottom: 12px; }
.typing-row:not([hidden]) { display: flex; }
.typing-bubble {
  display: flex; align-items: center; gap: 4px;
  background: var(--card-bg); border-radius: 17px; border-bottom-left-radius: 5px;
  padding: 13px 16px;
}
.typing-dot { width: 6px; height: 6px; border-radius: 50%; background: #8FAD6F; animation: typing-bounce 1.2s infinite; }
.typing-dot:nth-child(2) { animation-delay: 0.15s; }
.typing-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-3px); opacity: 1; }
}

.session-summary {
  background: var(--card-bg); border: 1px solid var(--line);
  border-radius: 14px; padding: 14px 16px; margin: 4px 0 16px;
}
.session-summary-link {
  display: inline-block; margin-top: 8px; font-size: 13px; color: var(--accent-dark); font-weight: 700;
}

/* ---- 下タブバー ---- */
.tab-bar {
  position: fixed; bottom: 0; left: 0; right: 0;
  max-width: 480px; margin: 0 auto;
  display: flex;
  background: rgba(255, 253, 246, 0.94);
  border-top: 1px solid var(--line);
  /* iPhoneのホームインジケーターと干渉しないよう、safe-area分＋余分なバッファを純粋な余白として確保する */
  padding-bottom: calc(env(safe-area-inset-bottom) + 10px);
  backdrop-filter: blur(6px);
}
.tab {
  flex: 1; display: flex; justify-content: center; align-items: center;
  min-height: 54px;
  color: #ADBB98; text-decoration: none;
}
.tab-icon {
  width: 23px; height: 23px;
  stroke: currentColor; fill: none;
  stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round;
}
.tab.active { color: var(--accent-dark); }
.tab.active .tab-icon { stroke-width: 2; filter: drop-shadow(0 0 3px rgba(124, 154, 92, 0.45)); }

/* ---- 認証画面 ---- */
.auth-page {
  max-width: 340px; margin: 60px auto; padding: 28px 24px;
  background: var(--card-bg); border: 1px solid var(--line); border-radius: 18px;
}
.auth-page h1 {
  font-family: "Hiragino Maru Gothic ProN", sans-serif; font-size: 22px; margin: 0 0 20px; color: var(--ink);
}
.auth-page p { font-size: 13px; margin-top: 14px; }
.auth-page a { color: var(--accent-dark); }
.auth-page .errors { color: var(--stamp); font-size: 13px; padding-left: 18px; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; color: var(--sub); margin-bottom: 4px; }
.field input {
  width: 100%; padding: 9px 11px; box-sizing: border-box;
  border: 1px solid var(--line); border-radius: 10px; background: var(--cream);
  /* 16px未満だとiOS Safariがフォーカス時に自動拡大してしまうため */
  font-size: 16px;
}

button, input[type="submit"] {
  padding: 10px 16px; border-radius: 999px; border: none;
  background: var(--accent); color: var(--cream); font-size: 14px; font-weight: 700;
  margin: 4px 0; cursor: pointer;
}

/* ---- 右上メニュー（ログアウトなど） ---- */
.page-menu {
  position: fixed; top: 0; left: 0; right: 0;
  max-width: 480px; margin: 0 auto; height: 0; z-index: 30;
}
.menu-btn {
  position: absolute; top: calc(16px + env(safe-area-inset-top)); right: 20px;
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--card-bg); border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center;
}
.menu-icon {
  width: 17px; height: 17px; flex-shrink: 0;
  fill: var(--accent-dark); stroke: none;
}
.menu-dropdown {
  display: none;
  position: absolute; top: calc(52px + env(safe-area-inset-top)); right: 20px;
  background: var(--cream); border: 1px solid var(--line); border-radius: 12px;
  padding: 6px; min-width: 120px;
  box-shadow: 0 10px 28px -10px rgba(60, 74, 52, 0.35);
}
.menu-dropdown.is-open { display: block; }
.menu-dropdown-item {
  width: 100%; text-align: left; background: transparent; color: var(--ink);
  font-size: 13px; font-weight: 400; padding: 9px 11px; border-radius: 8px; margin: 0;
}

/* ---- ホームのタブ切り替え（最近の挑戦／ここまでの歩み／最近の記録） ---- */
.home-tab-bar {
  display: flex; gap: 4px; margin-bottom: 16px;
  background: rgba(255, 253, 246, 0.5); border-radius: 12px; padding: 4px;
}
.home-tab-btn {
  flex: 1; text-align: center; padding: 9px 4px; border-radius: 9px; border: none;
  background: transparent; font-size: 12px; color: var(--sub); font-weight: 400;
}
.home-tab-btn.is-active {
  background: var(--card-bg); color: var(--accent-dark); font-weight: 700;
  box-shadow: 0 2px 8px -4px rgba(80, 100, 60, 0.35);
}
.home-tab-panel { display: none; }
.home-tab-panel.is-active { display: block; }

/* ---- これまでの記録（履歴一覧） ---- */
.history-page { position: relative; padding: 30px 20px 24px; }
.history-page h1 {
  font-family: "Hiragino Maru Gothic ProN", sans-serif; font-size: 22px; margin: 4px 0 20px; color: var(--ink);
}
.check-in-history { list-style: none; margin: 0; padding: 0; }
.check-in-history li { border-bottom: 1px solid var(--line-soft); }
.check-in-history a {
  display: block; padding: 10px 0; font-size: 13px; color: var(--ink); text-decoration: none;
}
