/* ===== 基本 ===== */
:root {
  --card: #ffffff;
  --text: #4a3f35;
  --text-sub: #9b8d7f;
  --success: #7fb069;
  --stamp-red: #e05c5c;
  --comeback-gold: #e8b634;
  --shadow: 0 2px 10px rgba(120, 90, 50, 0.10);
  --radius: 18px;
  --nav-height: 62px;
  /* テーマ既定＝クリーム（従来の配色） */
  --bg: #fdf6ec;
  --surface: #fffdf8;
  --soft: #f9efdd;
  --soft2: #efe3cd;
  --accent: #f4a259;
  --accent-deep: #e07a3f;
  --line: #f0e6d8;
}

/* ===== 配色テーマ ===== */
body.theme-pink {
  --bg: #fcf0f2; --surface: #fffbfc; --soft: #fbe7ea; --soft2: #f4d7dc;
  --accent: #e79aa6; --accent-deep: #c96e82; --line: #f5dde2;
}
body.theme-peach {
  --bg: #fdf6ec; --surface: #fffdf8; --soft: #f9efdd; --soft2: #efe3cd;
  --accent: #f4a259; --accent-deep: #e07a3f; --line: #f0e6d8;
}
/* ラベンダー */
body.theme-lavender {
  --bg: #f5f1f9; --surface: #fcfafe; --soft: #ece4f4; --soft2: #e0d2ec;
  --accent: #ab90cc; --accent-deep: #8b6cae; --line: #e8def2;
}
/* ミント */
body.theme-mint {
  --bg: #eff6f1; --surface: #fafdfb; --soft: #e2efe6; --soft2: #d3e6da;
  --accent: #82ba96; --accent-deep: #5f9d78; --line: #ddebe2;
}
/* そら */
body.theme-sky {
  --bg: #eff4f9; --surface: #fafcfe; --soft: #e3edf5; --soft2: #d4e2ee;
  --accent: #82aad1; --accent-deep: #5f8ab5; --line: #dfe9f2;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
  font-family: "Hiragino Maru Gothic ProN", "Hiragino Sans", "Yu Gothic", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100%;
  position: relative;
}

/* ===== ヘッダー ===== */
#header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 16px 18px 8px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}
#header h1 { font-size: 20px; letter-spacing: 1px; line-height: 1.25; }
.header-sub {
  display: block;
  font-size: 11px;
  color: var(--text-sub);
  font-weight: normal;
  letter-spacing: 0;
  white-space: nowrap;
}
#header-date { font-size: 13px; color: var(--text-sub); }

/* ===== メイン ===== */
#view {
  padding: 8px 14px calc(var(--nav-height) + 30px);
}

/* ===== 下部ナビ ===== */
#bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  height: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--surface);
  border-top: 1px solid var(--line);
  display: flex;
  z-index: 50;
}
.nav-btn {
  flex: 1;
  border: none;
  background: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  color: var(--text-sub);
  opacity: 0.65;
}
.nav-btn.active { opacity: 1; color: var(--accent-deep); }
.nav-icon { font-size: 20px; }
.nav-label { font-size: 10px; }

/* ===== 共通パーツ ===== */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}
.section-title {
  font-size: 14px;
  color: var(--text-sub);
  margin: 18px 4px 8px;
  font-weight: bold;
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 999px;
  padding: 10px 20px;
  font-size: 15px;
  font-weight: bold;
  cursor: pointer;
  font-family: inherit;
  background: var(--accent);
  color: #fff;
}
.btn:active { transform: scale(0.97); }
.btn.secondary { background: var(--soft2); color: var(--text); }
.btn.danger { background: #f3d1d1; color: #b04a4a; }
.btn.small { padding: 6px 14px; font-size: 13px; }
.btn.wide { width: 100%; padding: 13px; }
.btn:disabled { opacity: 0.45; cursor: default; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12px;
  background: var(--soft2);
  color: var(--text-sub);
  border: 1.5px solid transparent;
  cursor: pointer;
}
.chip.selected { border-color: var(--accent-deep); color: var(--accent-deep); background: var(--soft); }

.empty-note {
  text-align: center;
  color: var(--text-sub);
  font-size: 14px;
  padding: 30px 10px;
}

/* ===== 人タブ ===== */
#person-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 2px 10px;
  -webkit-overflow-scrolling: touch;
}
.person-tab {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 5px;
  border: 2px solid transparent;
  border-radius: 999px;
  background: #fff;
  box-shadow: var(--shadow);
  padding: 6px 14px;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  color: var(--text);
}
.person-tab.active { border-color: var(--tab-color, var(--accent-deep)); font-weight: bold; }

/* ===== 目的カード（ホーム） ===== */
.goal-card { position: relative; }
.goal-card .goal-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}
.goal-char {
  font-size: 38px;
  line-height: 1;
  width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--soft);
  border-radius: 14px;
  flex-shrink: 0;
}
.goal-info { flex: 1; min-width: 0; }
.goal-owner {
  font-size: 11px;
  font-weight: bold;
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  color: #fff;
  margin-bottom: 2px;
}
.goal-title { font-size: 16px; font-weight: bold; }
.goal-tags { margin-top: 2px; display: flex; flex-wrap: wrap; gap: 4px; }
.goal-tags .tag-mini {
  font-size: 10px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--soft2);
  color: var(--text-sub);
}
.goal-thumb {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  object-fit: cover;
  flex-shrink: 0;
  border: 2px solid var(--line);
}
.goal-step-row {
  margin-top: 10px;
  background: var(--soft);
  border-radius: 12px;
  padding: 10px 12px;
}
.goal-step-label { font-size: 11px; color: var(--text-sub); font-weight: bold; }
.goal-step-name { font-size: 15px; font-weight: bold; }
.progress-bar {
  height: 8px;
  background: var(--soft2);
  border-radius: 999px;
  margin-top: 6px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-deep));
  border-radius: 999px;
  transition: width 0.4s;
}
.progress-text { font-size: 12px; color: var(--text-sub); margin-top: 3px; text-align: right; }

.stamp-row {
  margin-top: 12px;
  display: flex;
  gap: 8px;
  align-items: center;
}
.stamp-btn {
  flex: 1;
  border: none;
  border-radius: 999px;
  padding: 13px;
  font-size: 16px;
  font-weight: bold;
  font-family: inherit;
  cursor: pointer;
  background: var(--stamp-red);
  color: #fff;
  box-shadow: 0 3px 0 #b84848;
}
.stamp-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #b84848; }
.stamp-btn.stamped {
  background: var(--soft2);
  color: var(--success);
  box-shadow: none;
  cursor: default;
}
.goal-done-badge {
  margin-top: 12px;
  text-align: center;
  font-weight: bold;
  color: var(--comeback-gold);
  font-size: 15px;
}
.detail-link {
  border: none;
  background: none;
  font-family: inherit;
  color: var(--text-sub);
  font-size: 12px;
  cursor: pointer;
  padding: 8px;
}

/* ===== 目的詳細（階段マップ） ===== */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--bg);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.overlay-inner { max-width: 480px; margin: 0 auto; padding: 14px 16px 60px; }
.overlay-top {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  position: sticky;
  top: 0;
  background: var(--bg);
  padding: 8px 0;
  z-index: 5;
}
.back-btn {
  border: none;
  background: #fff;
  box-shadow: var(--shadow);
  border-radius: 999px;
  width: 38px;
  height: 38px;
  font-size: 17px;
  cursor: pointer;
}
.overlay-title { font-size: 17px; font-weight: bold; flex: 1; }

.summit {
  text-align: center;
  background: linear-gradient(180deg, var(--soft), #ffffff);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 16px;
  margin-bottom: 6px;
}
.summit .summit-flag { font-size: 26px; }
.summit-images { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin: 8px 0; }
.summit-images img {
  width: 110px;
  height: 110px;
  object-fit: cover;
  border-radius: 14px;
  border: 3px solid var(--comeback-gold);
  cursor: pointer;
}
.summit-vow { font-size: 14px; font-weight: bold; color: var(--accent-deep); margin-top: 4px; }
.summit-goal-title { font-size: 17px; font-weight: bold; }
.summit-deadline { font-size: 12px; color: var(--text-sub); }

.stairs { position: relative; padding: 10px 0 4px; }
.stair-step {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 10px 0;
}
.stair-connector {
  width: 3px;
  height: 18px;
  background: var(--line);
  margin-left: 24px;
}
.stair-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 21px;
  flex-shrink: 0;
  background: var(--soft2);
}
.stair-step.cleared .stair-icon { background: #e2f0d9; }
.stair-step.current .stair-icon { background: var(--soft); box-shadow: 0 0 0 3px var(--accent); }
.stair-step.locked { opacity: 0.5; }
.stair-body { flex: 1; background: #fff; border-radius: 14px; box-shadow: var(--shadow); padding: 10px 14px; }
.stair-name { font-weight: bold; font-size: 15px; }
.stair-meta { font-size: 12px; color: var(--text-sub); }
.stair-actions { display: flex; gap: 6px; margin-top: 6px; }

.char-panel {
  text-align: center;
  padding: 16px;
}
.char-big { font-size: 64px; line-height: 1.2; }
.char-stage-name { font-weight: bold; font-size: 15px; margin-top: 4px; }
.char-note { font-size: 12px; color: var(--text-sub); }

.mini-stats {
  display: flex;
  gap: 8px;
  margin: 10px 0;
}
.mini-stat {
  flex: 1;
  background: #fff;
  border-radius: 14px;
  box-shadow: var(--shadow);
  text-align: center;
  padding: 10px 4px;
}
.mini-stat .num { font-size: 20px; font-weight: bold; color: var(--accent-deep); }
.mini-stat .label { font-size: 10px; color: var(--text-sub); }

/* ===== カレンダー ===== */
.cal-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 6px 2px 10px;
}
.cal-nav button {
  border: none;
  background: #fff;
  box-shadow: var(--shadow);
  border-radius: 999px;
  width: 36px;
  height: 36px;
  font-size: 15px;
  cursor: pointer;
}
.cal-month-label { font-size: 17px; font-weight: bold; }
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.cal-dow {
  text-align: center;
  font-size: 11px;
  color: var(--text-sub);
  padding: 4px 0;
}
.cal-day {
  min-height: 52px;
  background: #fff;
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 4px;
  font-size: 12px;
  cursor: pointer;
  position: relative;
}
.cal-day.empty { background: transparent; box-shadow: none; cursor: default; }
.cal-day.today { outline: 2px solid var(--accent); }
.cal-day .d-num { color: var(--text-sub); }
.cal-dots { display: flex; flex-wrap: wrap; gap: 2px; margin-top: 2px; }
.cal-dot { width: 8px; height: 8px; border-radius: 50%; }
.cal-comeback {
  position: absolute;
  top: 2px;
  right: 3px;
  font-size: 10px;
}

/* ===== 統計 ===== */
.stat-goal-card .stat-nums {
  display: flex;
  gap: 6px;
  margin-top: 10px;
}
.stat-box {
  flex: 1;
  background: var(--soft);
  border-radius: 12px;
  text-align: center;
  padding: 8px 2px;
}
.stat-box .num { font-size: 19px; font-weight: bold; color: var(--accent-deep); }
.stat-box .label { font-size: 10px; color: var(--text-sub); }
.stat-box.comeback .num { color: var(--comeback-gold); }

/* ===== 設定 ===== */
.settings-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--line);
}
.settings-row:last-child { border-bottom: none; }
.settings-row .grow { flex: 1; }
.color-dot { width: 16px; height: 16px; border-radius: 50%; flex-shrink: 0; }
.icon-btn {
  border: none;
  background: var(--soft2);
  border-radius: 8px;
  width: 30px;
  height: 30px;
  cursor: pointer;
  font-size: 13px;
}

/* ===== モーダル ===== */
#modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(60, 45, 30, 0.45);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
#modal-backdrop.hidden { display: none; }
#modal {
  background: var(--bg);
  border-radius: 22px 22px 0 0;
  width: 100%;
  max-width: 480px;
  max-height: 88vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 20px 18px calc(26px + env(safe-area-inset-bottom, 0px));
  animation: slideUp 0.25s ease;
}
@keyframes slideUp { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-title { font-size: 17px; font-weight: bold; margin-bottom: 14px; }
.form-group { margin-bottom: 16px; }
.form-label { font-size: 13px; font-weight: bold; color: var(--text-sub); display: block; margin-bottom: 5px; }
input[type="text"], input[type="number"], input[type="date"], textarea, select {
  width: 100%;
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 15px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); }
.chips-wrap { display: flex; flex-wrap: wrap; gap: 6px; }
.color-swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.color-swatch {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  border: 3px solid transparent;
}
.color-swatch.selected { border-color: var(--text); }
.theme-swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.theme-swatch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 2px solid var(--line);
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 13px;
  font-weight: bold;
  font-family: inherit;
  cursor: pointer;
  color: var(--text);
  background: #fff;
}
.theme-swatch.selected { border-color: var(--accent-deep); box-shadow: 0 0 0 2px var(--soft); }
.theme-dot { width: 14px; height: 14px; border-radius: 50%; flex-shrink: 0; border: 1px solid rgba(0,0,0,0.08); }
.emoji-swatches { display: flex; gap: 6px; flex-wrap: wrap; }
.emoji-swatch {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 2px solid transparent;
  background: #fff;
  font-size: 20px;
  cursor: pointer;
}
.emoji-swatch.selected { border-color: var(--accent-deep); background: var(--soft); }

.egg-choices { display: flex; gap: 8px; }
.egg-choice {
  flex: 1;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: #fff;
  padding: 10px 4px;
  text-align: center;
  cursor: pointer;
  font-family: inherit;
}
.egg-choice.selected { border-color: var(--accent-deep); background: var(--soft); }
.egg-choice .egg-emoji { font-size: 28px; }
.egg-choice .egg-name { font-size: 12px; font-weight: bold; }
.egg-choice .egg-desc { font-size: 10px; color: var(--text-sub); }

.step-edit-item { margin-bottom: 10px; }
.step-edit-row {
  display: flex;
  gap: 6px;
  align-items: center;
}
.step-range-hint {
  font-size: 11px;
  color: var(--text-sub);
  margin: 3px 0 0 26px;
}
.step-edit-row .step-num { font-size: 12px; color: var(--text-sub); width: 20px; flex-shrink: 0; }
.step-edit-row input.step-name-input { flex: 1; }
.step-edit-row input.step-days-input { width: 64px; flex-shrink: 0; text-align: center; }
.step-edit-row .days-label { font-size: 12px; color: var(--text-sub); flex-shrink: 0; }

.image-preview-wrap { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.image-preview {
  position: relative;
  width: 76px;
  height: 76px;
}
.image-preview img { width: 100%; height: 100%; object-fit: cover; border-radius: 12px; }
.image-preview .remove-img {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: var(--text);
  color: #fff;
  font-size: 11px;
  cursor: pointer;
}
.modal-actions { display: flex; gap: 8px; margin-top: 20px; }
.modal-actions .btn { flex: 1; }

/* ===== スタンプ演出 ===== */
#celebration {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(60, 45, 30, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
}
#celebration.hidden { display: none; }
.celebration-card {
  background: #fff;
  border-radius: 24px;
  padding: 30px 26px;
  text-align: center;
  max-width: 320px;
  width: 86%;
  animation: popIn 0.35s cubic-bezier(0.2, 1.6, 0.4, 1);
}
@keyframes popIn { from { transform: scale(0.6); opacity: 0; } to { transform: none; opacity: 1; } }
.stamp-mark {
  width: 130px;
  height: 130px;
  margin: 0 auto 12px;
  border-radius: 50%;
  border: 5px solid var(--stamp-red);
  color: var(--stamp-red);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  transform: rotate(-8deg);
  animation: stampIn 0.4s cubic-bezier(0.2, 1.8, 0.4, 1) 0.1s both;
}
@keyframes stampIn { from { transform: scale(2.2) rotate(-8deg); opacity: 0; } to { transform: scale(1) rotate(-8deg); opacity: 1; } }
.stamp-mark.comeback { border-color: var(--comeback-gold); color: var(--comeback-gold); }
.stamp-mark .stamp-emoji { font-size: 34px; }
.stamp-mark .stamp-text { font-size: 15px; }
.celebration-sub { font-size: 14px; color: var(--text-sub); margin-bottom: 8px; }
.celebration-char { font-size: 52px; margin: 6px 0; }
.evolution-arrow { font-size: 20px; color: var(--text-sub); margin: 0 8px; }
.celebration-extra { font-weight: bold; color: var(--accent-deep); font-size: 15px; margin-top: 6px; }

/* 画像全画面 */
.fullimg-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 15, 10, 0.9);
  z-index: 400;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  cursor: pointer;
}
.fullimg-backdrop img { max-width: 100%; max-height: 75vh; border-radius: 14px; }
.fullimg-vow { color: #ffd97a; font-weight: bold; margin-top: 14px; font-size: 16px; text-align: center; }

.hidden { display: none !important; }
