:root {
  --bg: #FDF6EC;
  --card: #FFFDF9;
  --line: #EFE2D1;
  --line-strong: #E3D2BC;
  --ink: #3A2A1E;
  --sub: #7C6654;
  --muted: #A8927E;
  --soft: #F6EBDD;
  --lv3: #E2553A;
  --lv2: #5B8F5A;
  --lv1: #E8A33A;
  --lv0: #B9AFA3;
  --accent: #E2553A;
  --danger: #C2402A;
  --radius: 18px;
  font-family: "Hiragino Maru Gothic ProN", "Hiragino Sans", "Zen Maru Gothic", "M PLUS Rounded 1c",
    "Noto Sans JP", "Yu Gothic", system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); }
body { min-height: 100vh; line-height: 1.6; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
a { color: var(--accent); }
[hidden] { display: none !important; }

.wrap {
  max-width: 640px;
  margin: 0 auto;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(48px + env(safe-area-inset-bottom));
}
.loading { color: var(--sub); text-align: center; margin-top: 30vh; }

/* 見出し */
.date { color: var(--sub); font-size: 14px; font-weight: 700; margin: 4px 0 0; }
h1 { font-size: 26px; line-height: 1.3; margin: 2px 0 8px; letter-spacing: .02em; }
h1 .num { font-size: 30px; }
h2 { font-size: 20px; margin: 32px 0 10px; }
.lead { color: var(--sub); font-size: 14px; margin: 0 0 10px; }
.note {
  background: var(--card); border-radius: 14px; padding: 12px 14px;
  color: var(--sub); font-size: 13px; margin: 0 0 14px;
}
.progress { height: 12px; background: #F3E6D4; border-radius: 99px; overflow: hidden; }
.progress > span { display: block; height: 100%; width: var(--w, 0%); background: var(--accent); border-radius: 99px; transition: width .4s; }

/* カード */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; margin: 0 0 12px;
}
.card h3 { margin: 0 0 4px; font-size: 17px; }

/* 自分の記録 */
.levels { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 12px; }
.lv-btn {
  border: 2px solid var(--line); background: #fff; border-radius: 16px;
  padding: 14px 8px; text-align: center; font-weight: 700; font-size: 17px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.lv-btn small { font-weight: 400; color: var(--sub); font-size: 12px; }
.lv-btn .dot { width: 14px; height: 14px; }
.lv-btn[aria-pressed="true"] { border-color: var(--c); background: color-mix(in srgb, var(--c) 12%, white); }
.lv-btn[aria-pressed="true"] small { color: var(--ink); }
.lv-btn:active { transform: scale(.97); }
.day-chips { display: flex; gap: 6px; overflow-x: auto; padding: 4px 0 8px; margin-top: 10px; scrollbar-width: none; }
.day-chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; border: 1px solid var(--line-strong); background: #fff; border-radius: 99px;
  padding: 6px 12px; font-size: 13px; display: inline-flex; align-items: center; gap: 6px;
}
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: #fff; }
.linkbtn { background: none; border: 0; padding: 4px 0; color: var(--sub); font-size: 13px; text-decoration: underline; }
.row { display: flex; align-items: center; gap: 10px; justify-content: space-between; flex-wrap: wrap; }

/* メンバー */
.member { display: flex; gap: 12px; align-items: flex-start; }
.avatar {
  flex: 0 0 auto; width: 48px; height: 48px; border-radius: 50%; background: var(--c);
  color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 20px;
}
.avatar.sm { width: 28px; height: 28px; font-size: 13px; }
.member-body { flex: 1; min-width: 0; }
.member-name { font-weight: 700; font-size: 17px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.tag { font-size: 11px; font-weight: 700; background: var(--soft); color: var(--sub); padding: 1px 8px; border-radius: 99px; }
.meta { color: var(--sub); font-size: 13px; }
.week { display: flex; gap: 8px; margin-top: 8px; }
.week .d { display: flex; flex-direction: column; align-items: center; font-size: 10px; color: var(--sub); gap: 2px; }
.dot { width: 13px; height: 13px; border-radius: 50%; border: 1.5px solid var(--line-strong); background: transparent; display: inline-block; }
.dot.l3 { background: var(--lv3); border-color: var(--lv3); }
.dot.l2 { background: var(--lv2); border-color: var(--lv2); }
.dot.l1 { background: var(--lv1); border-color: var(--lv1); }
.dot.l0 { background: var(--lv0); border-color: var(--lv0); }
.dot.future { border-style: dashed; opacity: .5; }
.side { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.pill { font-size: 13px; font-weight: 700; padding: 3px 12px; border-radius: 99px; background: var(--soft); color: var(--sub); white-space: nowrap; }
.pill.l3 { background: #FBE3DD; color: #A5341E; }
.pill.l2 { background: #E4EFE1; color: #3D6B3C; }
.pill.l1 { background: #FBEED6; color: #93600F; }
.pill.l0 { background: #EEEAE5; color: #6E655B; }
.cheer-btn {
  border: 1px solid var(--line-strong); background: #fff; border-radius: 99px;
  padding: 5px 12px; font-size: 13px; font-weight: 700; white-space: nowrap;
}
.cheer-count { font-size: 12px; color: var(--sub); }

/* グラフ */
.chart-head { display: flex; align-items: center; gap: 10px; }
.chart-head .name { font-weight: 700; flex: 1; }
.score { text-align: right; }
.score b { color: var(--accent); font-size: 26px; }
.score small { display: block; color: var(--sub); font-size: 12px; }
.chart { width: 100%; height: auto; display: block; margin-top: 8px; }
.chart text { font-size: 10px; fill: var(--sub); font-family: inherit; }
.chart .grid { stroke: #EFE5D8; stroke-width: 1; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 11px; color: var(--sub); margin-top: 6px; }
.legend span { display: inline-flex; align-items: center; gap: 4px; }
.legend .sq { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.sq.l3 { background: var(--lv3); } .sq.l2 { background: var(--lv2); } .sq.l1 { background: var(--lv1); }

/* 応援の記録 */
.empty { border: 1.5px dashed var(--line-strong); border-radius: var(--radius); padding: 22px; text-align: center; color: var(--sub); font-size: 14px; }
.cheer-item { display: flex; gap: 10px; align-items: flex-start; padding: 12px 0; border-top: 1px solid var(--line); }
.cheer-item:first-child { border-top: 0; padding-top: 0; }
.cheer-item .body { flex: 1; min-width: 0; font-size: 14px; }
.cheer-item .stamp { font-weight: 700; }
.cheer-item .msg { background: var(--soft); border-radius: 10px; padding: 6px 10px; margin-top: 4px; word-break: break-word; }
.cheer-item time { color: var(--muted); font-size: 12px; }
.icon-btn { background: none; border: 0; color: var(--muted); font-size: 12px; padding: 4px; text-decoration: underline; }

/* 管理 */
details.manage { margin-top: 32px; }
details.manage > summary { cursor: pointer; color: var(--sub); font-weight: 700; list-style: none; padding: 8px 0; }
details.manage > summary::-webkit-details-marker { display: none; }
details.manage > summary::after { content: " ▼"; font-size: 12px; }
details.manage[open] > summary::after { content: " ▲"; }
.field { display: flex; flex-direction: column; gap: 4px; margin: 0 0 12px; font-size: 13px; color: var(--sub); }
.input {
  width: 100%; border: 1.5px solid var(--line-strong); background: #fff; border-radius: 12px;
  padding: 11px 12px; font-size: 16px; color: var(--ink);
}
.input:focus { outline: none; border-color: var(--accent); }
.btn {
  border: 0; background: var(--ink); color: #fff; border-radius: 12px; padding: 12px 16px;
  font-weight: 700; font-size: 15px;
}
.btn.block { width: 100%; }
.btn.sub { background: #fff; color: var(--ink); border: 1.5px solid var(--line-strong); }
.btn.danger { background: #fff; color: var(--danger); border: 1.5px solid #EBC3BA; }
.btn.accent { background: var(--accent); }
.btn:disabled { opacity: .5; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }
.invite-box { background: var(--soft); border-radius: 12px; padding: 10px 12px; font-size: 13px; word-break: break-all; margin: 6px 0 10px; }
.mlist { list-style: none; padding: 0; margin: 0; }
.mlist li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.mlist li:first-child { border-top: 0; }
.mlist .nm { flex: 1; font-weight: 700; }
.small { font-size: 12px; color: var(--sub); }
.err { color: var(--danger); font-size: 13px; margin: 0 0 10px; }

/* ログイン画面 */
.auth { margin-top: 8vh; }
.brand { text-align: center; margin-bottom: 18px; }
.brand .logo { width: 64px; height: 64px; }
.brand h1 { margin-top: 6px; }
.tabs { display: flex; background: var(--soft); border-radius: 12px; padding: 4px; margin-bottom: 14px; }
.tabs button { flex: 1; border: 0; background: none; padding: 8px; border-radius: 9px; font-weight: 700; color: var(--sub); }
.tabs button[aria-selected="true"] { background: #fff; color: var(--ink); }

/* 下から出るシート */
.overlay { position: fixed; inset: 0; background: rgba(58, 42, 30, .35); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  background: var(--card); width: 100%; max-width: 640px; border-radius: 22px 22px 0 0;
  padding: 18px 16px calc(20px + env(safe-area-inset-bottom)); max-height: 90vh; overflow-y: auto;
  animation: up .2s ease-out;
}
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } .progress > span { transition: none; } }
.sheet h3 { margin: 0 0 12px; font-size: 18px; }
.stamps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.stamp-btn {
  border: 2px solid var(--line); background: #fff; border-radius: 14px; padding: 10px 4px;
  display: flex; flex-direction: column; align-items: center; font-size: 13px; font-weight: 700; gap: 2px;
}
.stamp-btn .e { font-size: 26px; line-height: 1.2; }
.stamp-btn[aria-pressed="true"] { border-color: var(--accent); background: #FDEEE9; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 99px; font-size: 14px;
  z-index: 30; max-width: 90vw; text-align: center;
}
.toast.error { background: var(--danger); }

@media (min-width: 560px) {
  .levels { grid-template-columns: repeat(4, 1fr); }
  h1 { font-size: 32px; }
}
