:root {
  --primary: #c2410c;
  --primary-light: #f97316;
  --bg: #fdf8f4;
  --card: #ffffff;
  --border: #ece0d5;
  --text: #2b1d12;
  --muted: #8a7565;
  --danger: #c0392b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  background: var(--primary);
  color: #fff;
  padding: 14px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.topbar a { color: #fff; text-decoration: none; }
.topbar .brand { font-weight: 700; font-size: 1.1rem; min-width: 0; }
.topbar form { margin: 0; }
.topbar button {
  background: rgba(255,255,255,0.15);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.6);
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
}
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-shrink: 0;
  margin-left: auto;
}
.bottombar .topbar-actions { margin-left: 0; }
.topbar-actions a {
  font-size: 0.85rem;
  border: 1px solid rgba(255,255,255,0.6);
  border-radius: 6px;
  padding: 6px 14px;
}

.bottombar { justify-content: flex-start; }
.bottombar .topbar-actions { gap: 20px; margin-left: 0; }

.settings-toggle { position: relative; display: inline-block; }
.settings-toggle summary {
  cursor: pointer;
  list-style: none;
  font-size: 0.85rem;
  border: 1px solid rgba(255,255,255,0.6);
  border-radius: 6px;
  padding: 6px 14px;
  color: #fff;
}
.settings-toggle summary::-webkit-details-marker { display: none; }
.settings-panel {
  position: absolute;
  bottom: 100%;
  left: 0;
  margin-bottom: 8px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 160px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.18);
  z-index: 20;
}
.settings-panel a,
.settings-panel button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 9px 10px;
  border-radius: 6px;
  color: var(--text);
  background: #fff;
  border: none;
  font-size: 0.9rem;
  cursor: pointer;
  text-decoration: none;
}
.settings-panel a:hover,
.settings-panel button:hover { background: var(--bg); }
.settings-panel form { margin: 0; }

/* --- 会員ページ専用のトップバー(名前の行とボタンの行を同じ高さに揃え、サービス名は小さく上に) --- */
.member-topbar {
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  padding-top: max(14px, env(safe-area-inset-top));
}
.topbar-eyebrow { font-weight: 700; font-size: 1.1rem; }
.topbar-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.member-topbar .topbar-actions { flex-wrap: wrap; justify-content: flex-end; row-gap: 6px; }

.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 20px;
}

h1, h2, h3 { margin-top: 0; }

.stat-row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.stat-box {
  flex: 1;
  min-width: 120px;
  background: #fdead9;
  border-radius: 8px;
  padding: 14px;
  text-align: center;
}

.stat-box .num { font-size: 1.8rem; font-weight: 700; color: var(--primary); }
.stat-box .label { font-size: 0.8rem; color: var(--muted); }

.checkin-btn {
  display: block;
  width: 100%;
  padding: 18px;
  font-size: 1.1rem;
  font-weight: 700;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  color: #fff;
  background: var(--primary-light);
}
.checkin-btn.checked { background: var(--muted); }

.calendar-nav {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 4px;
}
.calendar-nav .btn[disabled] {
  opacity: 0.4;
  cursor: default;
}

.grid-head {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-top: 12px;
}
.day-head {
  text-align: center;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
  padding-bottom: 4px;
}
.day-head.sat { color: #1d4ed8; }
.day-head.sun { color: #dc2626; }

.grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-top: 4px;
}
.grid .day {
  aspect-ratio: 1;
  border-radius: 4px;
  background: #ede4da;
  position: relative;
}
.grid .day.empty { background: transparent; }
.grid .day.checked { background: var(--primary-light); }
.grid .day .tip {
  position: absolute;
  bottom: -1.4em;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.6rem;
  color: var(--muted);
  white-space: nowrap;
  display: none;
}
.grid .day .daynum {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.62rem;
  color: var(--muted);
}
.grid .day.checked .daynum { color: #fff; font-weight: 700; }
.grid .day.sat:not(.checked) { background: #dbeafe; }
.grid .day.sun:not(.checked) { background: #fde2e1; }
.grid .day.sat .daynum { color: #1d4ed8; }
.grid .day.sun .daynum { color: #dc2626; }
.grid .day.checked.sat .daynum,
.grid .day.checked.sun .daynum { color: #fff; }

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 260px;
  overflow-y: auto;
}
.history-list li {
  padding: 8px 4px;
  border-bottom: 1px solid var(--border);
  font-size: 0.92rem;
}
.history-list li:last-child { border-bottom: none; }

/* --- トレーニングメモ --- */
.memo-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 420px;
  overflow-y: auto;
}
.memo-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  background: #fff;
}
.memo-item.has-memo {
  background: #fdead9;
  border-color: var(--primary-light);
}
.memo-item summary {
  cursor: pointer;
  padding: 2px 0;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 10px;
}
.memo-item summary::-webkit-details-marker { display: none; }
.memo-item summary::before { content: '▸'; color: var(--muted); flex-shrink: 0; }
.memo-item[open] summary::before { content: '▾'; }
.memo-date {
  font-weight: 700;
  font-size: 0.92rem;
  flex-shrink: 0;
}
.memo-preview {
  font-size: 0.88rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.memo-item.has-memo .memo-preview { color: var(--primary); }
.memo-item form {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.memo-item textarea {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 16px;
  font-family: inherit;
  resize: vertical;
}
.memo-item .btn { align-self: flex-start; }
.memo-month {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
  background: #fff;
}
.memo-month:last-child { margin-bottom: 0; }
.memo-month-summary {
  cursor: pointer;
  padding: 12px 14px;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 700;
  font-size: 0.95rem;
}
.memo-month-summary::-webkit-details-marker { display: none; }
.memo-month-count { font-weight: 400; font-size: 0.78rem; color: var(--muted); }
.memo-month .memo-list { padding: 0 12px 12px; }

.rankup-toggle summary { cursor: pointer; list-style: none; font-weight: 700; font-size: 0.95rem; padding: 2px 0; }
.rankup-toggle summary::-webkit-details-marker { display: none; }
.rankup-toggle summary::before { content: '▸ '; color: var(--muted); }
.rankup-toggle[open] summary::before { content: '▾ '; }
.rankup-toggle .history-list { max-height: 200px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); font-size: 0.92rem; }
th { color: var(--muted); font-weight: 600; }
tr:hover { background: #fafcfa; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 12px; font-size: 0.75rem; }
.badge.good { background: #ffe1b8; color: var(--primary); }
.badge.warn { background: #fdecea; color: var(--danger); }

.btn {
  display: inline-block;
  padding: 8px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  text-decoration: none;
  color: var(--text);
  font-size: 0.9rem;
}
.btn.primary { background: var(--primary); color: #fff; border: none; }
.btn.danger { color: var(--danger); border-color: var(--danger); }

.form-row { margin-bottom: 10px; }
.form-row label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 4px; }
.form-row input {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 16px; /* iOSでフォーカス時に勝手に拡大ズームされるのを防ぐ */
}
.form-row textarea {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 16px; /* iOSでフォーカス時に勝手に拡大ズームされるのを防ぐ */
  font-family: inherit;
  resize: vertical;
}

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* --- 会員の体の情報(履歴) --- */
.body-info-history { display: flex; flex-direction: column; gap: 10px; max-height: 320px; overflow-y: auto; }
.body-info-entry { padding: 10px 12px; background: #fdead9; border-radius: 8px; font-size: 0.85rem; }
.body-info-date { font-weight: 700; color: var(--primary); margin-bottom: 4px; font-size: 0.8rem; }
.body-info-stats { margin-bottom: 4px; }
.body-info-field { margin-top: 8px; white-space: pre-wrap; word-break: break-word; }
.body-info-field-label { font-size: 0.78rem; color: var(--muted); font-weight: 700; margin-bottom: 2px; }

.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; }
.inline-form .form-row { flex: 1; min-width: 140px; margin-bottom: 0; }

.error { color: var(--danger); margin-bottom: 12px; font-size: 0.9rem; }
.message { color: var(--primary); margin-bottom: 12px; font-size: 0.9rem; }

.body-check-photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; margin-top: 4px; }
.body-check-photo-item { border: 1px solid var(--border); border-radius: 8px; padding: 8px; background: var(--bg); text-align: center; }
.body-check-guide-img { width: 100%; aspect-ratio: 3/4; object-fit: cover; border-radius: 6px; background: #eee; }

/* --- サイトの使い方ページ --- */
.howto-steps { display: flex; flex-direction: column; gap: 14px; }
.howto-step { display: flex; gap: 12px; align-items: flex-start; }
.howto-step-num { font-size: 1.3rem; color: var(--primary); flex-shrink: 0; line-height: 1.4; }
.howto-step-title { font-weight: 700; margin-bottom: 2px; }
.howto-step-desc { font-size: 0.85rem; color: var(--muted); line-height: 1.5; }

.howto-addhome { display: flex; flex-wrap: wrap; gap: 16px; }
.howto-addhome-item { flex: 1; min-width: 220px; background: #fdead9; border-radius: 8px; padding: 14px 16px; }
.howto-addhome-item h3 { margin: 0 0 8px; font-size: 1rem; }
.howto-addhome-item ol { margin: 0; padding-left: 1.2em; }
.howto-addhome-item li { font-size: 0.85rem; line-height: 1.6; margin-bottom: 4px; }
.howto-addhome-item li:last-child { margin-bottom: 0; }
.body-check-photo-label { font-size: 0.75rem; color: var(--muted); margin: 6px 0 4px; }
.body-check-photo-item input[type="file"] { width: 100%; font-size: 0.7rem; }

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card { width: 320px; }

/* --- バッジ --- */
.badge-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 8px;
}
.badge-item {
  flex: 1;
  min-width: 84px;
  text-align: center;
  padding: 12px 6px;
  border-radius: 10px;
  background: #f2ece5;
  opacity: 0.45;
  filter: grayscale(1);
}
.badge-item.unlocked {
  opacity: 1;
  filter: none;
  background: #fdead9;
  box-shadow: 0 0 0 2px var(--primary-light) inset;
}
.badge-item .icon { font-size: 1.8rem; display: block; margin-bottom: 4px; }
.badge-item .label { font-size: 0.68rem; color: var(--muted); line-height: 1.2; }

/* --- ランキング --- */
.leaderboard { list-style: none; margin: 0; padding: 0; }
.leaderboard li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 4px;
  border-bottom: 1px solid var(--border);
  font-size: 0.92rem;
}
.leaderboard li:last-child { border-bottom: none; }
.leaderboard .rank {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #f2ece5;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.8rem;
  flex-shrink: 0;
}
.leaderboard li.rank-1 .rank { background: #ffe08a; color: #7a5b00; }
.leaderboard li.rank-2 .rank { background: #dfe3e6; color: #52565a; }
.leaderboard li.rank-3 .rank { background: #eac9a2; color: #6b4413; }
.leaderboard li.me { background: #fdead9; border-radius: 8px; }
.leaderboard .name { flex: 1; }
.leaderboard .count { font-weight: 700; color: var(--primary); }

/* --- メニュー更新の進捗表示(スタンプカード風) --- */
.stamp-row {
  display: flex;
  justify-content: center;
  gap: 14px;
  margin: 6px 0 14px;
  flex-wrap: wrap;
}
.stamp {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 3px dashed var(--border);
  color: var(--muted);
  font-size: 1.4rem;
  font-weight: 700;
  flex-shrink: 0;
}
.stamp.filled {
  border: 3px solid var(--primary);
  background: #fdead9;
  color: var(--primary);
  font-size: 1.9rem;
  transform: rotate(-8deg);
  box-shadow: 0 0 0 3px #fff inset, 0 0 0 4px var(--primary-light) inset;
}
.menu-ready {
  background: linear-gradient(135deg, #f4a261, #e9a600);
  color: #fff;
  border-radius: 10px;
  padding: 14px 16px;
  margin-top: 10px;
  text-align: center;
  font-weight: 700;
  font-size: 1.05rem;
  box-shadow: 0 0 0 3px #ffe08a inset;
}
.menu-ready .sub { font-weight: 400; font-size: 0.85rem; opacity: 0.95; margin-top: 4px; }

/* --- 新着メッセージ通知 --- */
.notify-banner {
  display: block;
  background: #fdead9;
  color: var(--primary);
  border: 1px solid var(--primary-light);
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 20px;
  text-align: center;
  font-weight: 700;
  font-size: 0.95rem;
  text-decoration: none;
}

/* --- トレーニングライブラリ(会員間で動画・画像・コンテンツを使い回す) --- */
.library-list { max-height: 340px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; }
.library-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.library-item:last-child { border-bottom: none; }
.library-item-info { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1; }
.library-item-icon { font-size: 1.1rem; flex-shrink: 0; }
.library-item-title { font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.library-item-actions { display: flex; gap: 6px; flex-shrink: 0; }
.library-item-actions form { margin: 0; }
.library-item-actions .btn { padding: 6px 12px; font-size: 0.85rem; }

/* --- お祝い演出 --- */
.celebrate-banner {
  background: linear-gradient(135deg, #f97316, #c2410c);
  color: #fff;
  border-radius: 10px;
  padding: 18px 20px;
  margin-bottom: 20px;
  text-align: center;
  font-weight: 700;
  font-size: 1.05rem;
}
.celebrate-banner .sub { font-weight: 400; font-size: 0.85rem; opacity: 0.9; margin-top: 4px; }
.celebrate-banner.reward {
  background: linear-gradient(135deg, #f4a261, #e9a600);
  font-size: 1.25rem;
  padding: 22px 20px;
  box-shadow: 0 0 0 3px #ffe08a inset;
}

.confetti-piece {
  position: fixed;
  top: -10px;
  width: 8px;
  height: 14px;
  z-index: 999;
  pointer-events: none;
  animation: confetti-fall linear forwards;
}
@keyframes confetti-fall {
  to {
    transform: translateY(105vh) rotate(540deg);
    opacity: 0.3;
  }
}

/* --- 会員専用の動画 --- */
.video-list {
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.video-item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.video-item-head h4 { margin: 0; font-size: 0.95rem; }
.video-item-head form { margin: 0; }
.video-item-title {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  min-width: 0;
}
.video-item-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.video-item-actions form { margin: 0; }
.video-item-actions .btn { padding: 6px 10px; }
.video-embed {
  position: relative;
  width: 100%;
  padding-top: 56.25%; /* 16:9 */
  border-radius: 8px;
  overflow: hidden;
  background: #000;
}
.video-embed iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: 0;
}
.training-photo {
  display: block;
  width: 100%;
  max-height: 400px;
  object-fit: contain;
  border-radius: 8px;
  background: #f2ece5;
}
.interactive-embed {
  position: relative;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  height: 480px; /* JSでコンテンツの実際の高さに自動調整される(これは読み込み前の仮の高さ) */
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #fff;
}
.interactive-embed iframe {
  width: 100%;
  height: 100%;
  border: 0;
}
.training-reps {
  display: inline-block;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--primary);
  background: #fdead9;
  border-radius: 8px;
  padding: 4px 10px;
}
.reps-edit-form {
  display: flex;
  align-items: center;
  gap: 6px;
}
.reps-edit-form input {
  width: 140px;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 16px; /* iOSでフォーカス時に勝手に拡大ズームされるのを防ぐ */
}
.reps-edit-form .btn { flex-shrink: 0; padding: 5px 10px; font-size: 0.8rem; }

/* --- 管理者⇔会員のメッセージ --- */
.msg-thread {
  max-height: 320px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
}
.msg-bubble {
  max-width: 80%;
  padding: 8px 12px;
  border-radius: 12px;
  background: #f2ece5;
}
.msg-bubble.from-admin {
  align-self: flex-start;
  background: #f2ece5;
  border-bottom-left-radius: 2px;
}
.msg-bubble.from-member {
  align-self: flex-end;
  background: #ffe1b8;
  border-bottom-right-radius: 2px;
}
.msg-meta { font-size: 0.7rem; color: var(--muted); margin-bottom: 2px; }
.msg-body { font-size: 0.9rem; white-space: pre-wrap; word-break: break-word; }

/* --- 掲示板 --- */
.board-post-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 6px;
}
.board-post-body { font-size: 0.95rem; white-space: pre-wrap; word-break: break-word; }
.board-reply {
  margin-top: 10px;
  margin-left: 16px;
  padding: 8px 12px;
  background: #fdead9;
  border-radius: 8px;
  border-left: 3px solid var(--primary-light);
}
.board-reply-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 3px;
}
.board-reply-body { font-size: 0.88rem; white-space: pre-wrap; word-break: break-word; }
.board-reply-form { margin-top: 10px; }
.board-reply-form .form-row { flex: 1; margin-bottom: 0; }

/* --- スマホ向けの余白調整(会員は基本スマホ操作を想定) --- */
@media (max-width: 480px) {
  .container { padding: 14px; }
  .card { padding: 16px; margin-bottom: 14px; }
  .topbar { padding: 12px 16px; }
  .stat-box { min-width: 100px; padding: 12px; }
  .stat-box .num { font-size: 1.5rem; }
  .badge-item { min-width: 70px; padding: 10px 4px; }
  .badge-item .icon { font-size: 1.5rem; }
  .checkin-btn { padding: 16px; font-size: 1rem; }
  th, td { padding: 8px 6px; font-size: 0.85rem; }
  .topbar { flex-wrap: nowrap; gap: 8px; }
  .topbar-actions { gap: 10px; }
  .topbar-actions a { font-size: 0.78rem; padding: 5px 8px; white-space: nowrap; }
  .topbar .brand { font-size: 0.95rem; }
  .msg-bubble { max-width: 92%; }
  .board-reply { margin-left: 8px; }
}
