:root {
  --bg: #F7F4EC;
  --card: #FFFDF8;
  --ink: #3F4652;
  --sub: #7B828D;
  --line: #E7E2D6;
  --blue: #CFE0EF;
  --blue-m: #A9C7E3;
  --blue-d: #6F97BF;
  --lav: #E4DFF2;
  --lav-d: #9C90C9;
  --yellow: #F1E3B5;
  --yellow-d: #C9A54E;
  --grey: #9AA1AB;
  --radius: 20px;
  --shadow: 0 2px 0 rgba(120, 110, 90, .05), 0 8px 24px rgba(120, 110, 90, .06);
  --nav-h: 64px;
  --font: "Hiragino Maru Gothic ProN", "Hiragino Maru Gothic Pro", "BIZ UDPGothic", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 400px at 50% -120px, #E6EEF6 0%, rgba(230, 238, 246, 0) 70%),
    var(--bg);
  line-height: 1.7;
  font-size: 15px;
  min-height: 100vh;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 8px);
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--blue-d); }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.shell { max-width: 560px; margin: 0 auto; padding: 0 16px; }
main { outline: none; }
.loading { padding: 80px 0; text-align: center; color: var(--sub); }

/* ---------- ナビ（スマホ：下部固定） ---------- */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(255, 253, 248, .94);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
}
.nav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  text-decoration: none; color: var(--sub); font-size: 11px;
}
.nav a .ni svg { width: 24px; height: 24px; display: block; }
.nav a[aria-current="page"] { color: var(--blue-d); font-weight: 700; }
.nav a[aria-current="page"] .ni { background: var(--blue); border-radius: 12px; padding: 2px 14px; }

/* ---------- ヘッダー ---------- */
.hero { padding: 28px 4px 18px; position: relative; }
.hero h1 { margin: 0; font-size: 26px; letter-spacing: .08em; }
.hero .copy { margin: 2px 0 0; color: var(--sub); font-size: 13px; }
.hero .today { margin-top: 10px; font-size: 13px; color: var(--ink); background: var(--card); display: inline-block; padding: 2px 12px; border-radius: 99px; border: 1px solid var(--line); }
.wave-deco { display: block; width: 100%; height: 18px; margin-top: 14px; }
.page-title { padding: 24px 4px 8px; }
.page-title h1 { margin: 0; font-size: 21px; letter-spacing: .06em; }
.page-title p { margin: 2px 0 0; color: var(--sub); font-size: 13px; }

/* ---------- カード ---------- */
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  border: 1px solid #EFEADF; padding: 18px; margin: 14px 0;
}
.card h2 { font-size: 15px; margin: 0 0 10px; letter-spacing: .05em; display: flex; align-items: center; gap: 8px; }
.card h2 .tag-n { margin-left: auto; font-size: 11px; color: var(--sub); font-weight: normal; }
.card h3 { font-size: 14px; margin: 16px 0 6px; }
.muted { color: var(--sub); }
.small { font-size: 12.5px; }
.note { font-size: 12px; color: var(--sub); margin: 8px 0 0; }

.today-card { display: grid; grid-template-columns: 92px 1fr; gap: 14px; align-items: center; }
.today-card .wx { width: 92px; height: 92px; }
.today-card .wx-name { font-size: 20px; font-weight: 700; margin: 0; }
.today-card .lv { margin: 0; color: var(--sub); font-size: 13px; }
.today-card .msg { margin: 6px 0 0; font-size: 13.5px; }
.empty-today { text-align: center; padding: 8px 0 4px; }
.empty-today .wx { width: 72px; height: 72px; opacity: .55; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip { font-size: 12px; padding: 2px 10px; border-radius: 99px; background: var(--blue); color: #46617D; }
.chip.lav { background: var(--lav); color: #5F5689; }
.chip.yel { background: var(--yellow); color: #7A6326; }
.chip.grey { background: #ECEDEF; color: #5E6470; }

/* ---------- ボタン ---------- */
.btn {
  appearance: none; border: 0; cursor: pointer;
  background: var(--blue-d); color: #fff; font-weight: 700;
  padding: 12px 20px; border-radius: 14px; min-height: 46px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  text-decoration: none; transition: transform .08s, filter .15s;
}
.btn:active { transform: scale(.98); }
.btn:disabled { background: #C7CDD5; cursor: not-allowed; }
.btn.block { width: 100%; }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); font-weight: normal; }
.btn.soft { background: var(--blue); color: #3E5E80; }
.btn.lav { background: var(--lav); color: #4F4680; }
.btn.danger { background: #EFE6E3; color: #8A5A4E; }
.btn.small { min-height: 36px; padding: 6px 14px; font-size: 13px; border-radius: 12px; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.linkish { background: none; border: 0; color: var(--blue-d); cursor: pointer; padding: 0; text-decoration: underline; font-size: 13px; }

/* ---------- 予報 ---------- */
.fc-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.fc {
  background: linear-gradient(180deg, #F3F7FB, #FFFDF8 70%);
  border: 1px solid #E9EEF3; border-radius: 16px; padding: 10px 8px 12px; text-align: center;
}
.fc .d { font-size: 12px; color: var(--sub); }
.fc .wx { width: 52px; height: 52px; display: block; margin: 2px auto; }
.fc .lbl { font-size: 12.5px; font-weight: 700; line-height: 1.4; min-height: 2.8em; display: flex; align-items: center; justify-content: center; }
.fc .rel { display: inline-block; font-size: 10.5px; margin-top: 6px; padding: 0 8px; border-radius: 99px; background: var(--lav); color: #5F5689; }
.fc .rel.trend { background: var(--blue); color: #46617D; }
.fc .rel.pending { background: #ECEDEF; color: #5E6470; }
.fc-reasons { margin-top: 12px; }
.fc-reasons details { border-top: 1px dashed var(--line); padding: 8px 2px; }
.fc-reasons summary { cursor: pointer; font-size: 13px; color: var(--ink); }
.fc-reasons ul { margin: 6px 0 0; padding-left: 1.2em; font-size: 12.5px; color: var(--sub); }
.fc-off { display: flex; gap: 12px; align-items: center; }
.fc-off .wx { width: 56px; height: 56px; flex: none; }
.fc-off p { margin: 0; }

.progress { height: 10px; background: #EEEAE0; border-radius: 99px; overflow: hidden; margin: 8px 0 4px; }
.progress > span { display: block; height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--blue-m), var(--lav-d)); }

/* ---------- グラフ ---------- */
.chart { display: block; overflow: visible; touch-action: pan-y; }
.chart .grid { stroke: #EDE8DC; stroke-width: 1; }
.chart .grid.base { stroke: #DDD6C6; }
.chart .tick { font-size: 10.5px; fill: #9AA0A8; }
.chart .line { fill: none; stroke-width: 2.6; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { stroke: #FFFDF8; stroke-width: 1.4; }
.chart .cursor { stroke: #C9C2B2; stroke-dasharray: 3 3; }
.chart-tip {
  position: absolute; top: -4px; transform: translateY(-100%);
  background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 6px 10px;
  font-size: 12px; box-shadow: var(--shadow); pointer-events: none; white-space: nowrap; z-index: 5;
}
.chart-tip b { display: block; font-size: 12px; }
.sw { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; vertical-align: 1px; }
.legend { display: flex; flex-wrap: wrap; gap: 10px; font-size: 12px; color: var(--sub); margin-top: 6px; }

.seg { display: flex; background: #F0ECE2; border-radius: 12px; padding: 3px; gap: 2px; }
.seg button { flex: 1; border: 0; background: transparent; border-radius: 10px; padding: 6px 0; cursor: pointer; font-size: 13px; color: var(--sub); }
.seg button[aria-pressed="true"] { background: var(--card); color: var(--ink); font-weight: 700; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.toggles { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 4px; }
.toggle { border: 1px solid var(--line); background: var(--card); border-radius: 99px; padding: 4px 12px; font-size: 12.5px; cursor: pointer; color: var(--sub); }
.toggle[aria-pressed="true"] { color: var(--ink); border-color: currentColor; font-weight: 700; }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.stat { background: #F8F6F0; border-radius: 14px; padding: 10px 12px; }
.stat .k { font-size: 11.5px; color: var(--sub); }
.stat .v { font-size: 20px; font-weight: 700; }
.stat .v small { font-size: 11px; font-weight: normal; color: var(--sub); margin-left: 4px; }

.bars { display: grid; gap: 6px; }
.bar-row { display: grid; grid-template-columns: 4.2em 1fr 5.6em; gap: 8px; align-items: center; font-size: 12.5px; }
.bar-row.muted { opacity: .45; }
.bar-track { height: 10px; background: #F0ECE2; border-radius: 99px; overflow: hidden; }
.bar-fill { display: block; height: 100%; border-radius: 99px; }
.bar-val { text-align: right; }
.bar-val small { color: var(--sub); font-size: 10.5px; }

.insight { margin: 8px 0 0; padding: 10px 12px; background: #F4F7FB; border-radius: 12px; font-size: 13.5px; }
.insight.lav { background: #F4F2FA; }
.cmp { width: 100%; border-collapse: collapse; font-size: 12.5px; margin-top: 8px; }
.cmp th, .cmp td { padding: 5px 4px; border-bottom: 1px solid #F0ECE2; text-align: right; }
.cmp th:first-child, .cmp td:first-child { text-align: left; }
.cmp th { color: var(--sub); font-weight: normal; font-size: 11.5px; }

.locked { display: flex; gap: 10px; align-items: center; color: var(--sub); font-size: 13px; }
.locked .lk { flex: none; width: 34px; height: 34px; border-radius: 50%; background: #F0ECE2; display: grid; place-items: center; font-size: 15px; }
.roadmap { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; font-size: 13px; }
.roadmap li { display: flex; gap: 8px; align-items: center; }
.roadmap .dt { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--line); flex: none; }
.roadmap li.on .dt { background: var(--blue-m); border-color: var(--blue-m); }
.roadmap li:not(.on) { color: var(--sub); }

/* ---------- 記録フォーム ---------- */
.date-bar { display: flex; align-items: center; gap: 8px; }
.date-bar .dlabel { flex: 1; text-align: center; font-weight: 700; font-size: 16px; }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: var(--card); cursor: pointer; font-size: 16px; color: var(--sub); }
.icon-btn:disabled { opacity: .35; cursor: default; }
.date-state { text-align: center; font-size: 12.5px; margin-top: 4px; color: var(--sub); }
.date-state.editing { color: var(--lav-d); font-weight: 700; }

.cal { margin-top: 12px; }
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; text-align: center; }
.cal-grid .wd { font-size: 11px; color: var(--sub); }
.cal-grid button {
  aspect-ratio: 1; border: 0; border-radius: 12px; background: transparent; cursor: pointer; font-size: 13px; position: relative;
}
.cal-grid button.has::after { content: ""; position: absolute; left: 50%; bottom: 5px; width: 5px; height: 5px; margin-left: -2.5px; border-radius: 50%; background: var(--blue-d); }
.cal-grid button.sel { background: var(--blue); font-weight: 700; }
.cal-grid button.today { outline: 1.5px solid var(--blue-m); }
.cal-grid button:disabled { color: #CCC; cursor: default; }

.field { margin-top: 18px; }
.field > .lab { display: flex; align-items: baseline; gap: 8px; font-weight: 700; font-size: 14px; margin-bottom: 8px; }
.field > .lab .opt { font-size: 11px; font-weight: normal; color: var(--sub); }
.field > .lab .req { font-size: 11px; font-weight: normal; color: var(--blue-d); }
.field > .lab .clear { margin-left: auto; }

.mot-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.mot {
  border: 1.5px solid transparent; background: #F6F3EC; border-radius: 16px; padding: 6px 2px 6px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 0;
}
.mot .wx { width: 38px; height: 38px; }
.mot .num { font-weight: 700; font-size: 15px; line-height: 1.2; }
.mot[aria-pressed="true"] { border-color: var(--blue-d); background: #EEF4FA; }
.mot-label { text-align: center; font-size: 13px; color: var(--sub); min-height: 1.6em; margin-top: 6px; }

.scale { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.scale button { border: 1.5px solid transparent; background: #F6F3EC; border-radius: 12px; padding: 8px 0; cursor: pointer; font-weight: 700; }
.scale.lav button[aria-pressed="true"] { border-color: var(--lav-d); background: var(--lav); }
.scale.yel button[aria-pressed="true"] { border-color: var(--yellow-d); background: var(--yellow); }
.scale-label { font-size: 12.5px; color: var(--sub); margin-top: 4px; min-height: 1.6em; }

.sleep-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
select, input[type="text"], textarea, input[type="date"] {
  border: 1px solid var(--line); background: #FFFEFB; border-radius: 12px; padding: 9px 12px; min-height: 44px;
}
select { padding-right: 28px; }
textarea { width: 100%; min-height: 84px; resize: vertical; }
input[type="text"] { width: 100%; }

.tagbox { display: flex; flex-wrap: wrap; gap: 6px; }
.tagbtn { border: 1px solid var(--line); background: #FFFEFB; border-radius: 99px; padding: 5px 12px; font-size: 13px; cursor: pointer; }
.tagbtn[aria-pressed="true"] { background: var(--lav); border-color: var(--lav-d); color: #4F4680; font-weight: 700; }

details.more { margin-top: 18px; border-top: 1px dashed var(--line); padding-top: 12px; }
details.more summary { cursor: pointer; font-size: 14px; font-weight: 700; color: var(--ink); }

.save-bar {
  position: sticky; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 8px); z-index: 5;
  margin-top: 18px; padding: 10px; background: rgba(247, 244, 236, .92); backdrop-filter: blur(6px); border-radius: 18px;
}

/* ---------- 設定 ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.taglist { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.taglist .t { display: inline-flex; align-items: center; gap: 2px; background: #F6F3EC; border-radius: 99px; padding: 3px 4px 3px 12px; font-size: 13px; }
.taglist .t button { border: 0; background: transparent; cursor: pointer; color: var(--sub); width: 26px; height: 26px; border-radius: 50%; }
.taglist .t button:hover { background: #ECE7DC; }
.add-row { display: flex; gap: 8px; margin-top: 10px; }
.add-row input { flex: 1; }
.prose p { margin: 6px 0; font-size: 13.5px; }
.prose ul { margin: 6px 0; padding-left: 1.2em; font-size: 13.5px; }

/* ---------- 共通 ---------- */
.footer { text-align: center; font-size: 11.5px; color: var(--sub); padding: 18px 0 14px; letter-spacing: .05em; }
.disclaimer { font-size: 11.5px; color: var(--sub); margin: 18px 4px 0; line-height: 1.7; }
#toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 20px); transform: translateX(-50%);
  background: #4A5160; color: #fff; padding: 10px 18px; border-radius: 99px; font-size: 13.5px; z-index: 50;
  box-shadow: 0 6px 20px rgba(0,0,0,.15); max-width: 90vw;
}
dialog { border: 0; border-radius: 22px; padding: 0; max-width: min(420px, 92vw); box-shadow: 0 20px 60px rgba(0,0,0,.2); background: var(--card); color: var(--ink); }
dialog::backdrop { background: rgba(60, 64, 72, .35); }
.dialog-body { padding: 22px; }
.dialog-body h2 { margin: 0 0 8px; font-size: 17px; }
#dialog-text { font-size: 14px; }
.dialog-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }
#demo-banner { background: var(--lav); color: #4F4680; font-size: 12.5px; padding: 8px 12px; text-align: center; }
#demo-banner select { min-height: 32px; padding: 2px 8px; font-size: 12.5px; margin: 0 6px; }
.noscript { text-align: center; padding: 40px; }

/* ---------- PC ---------- */
@media (min-width: 900px) {
  body { padding-bottom: 0; }
  .shell { max-width: 980px; display: grid; grid-template-columns: 180px 1fr; gap: 32px; padding-top: 24px; }
  .nav {
    position: sticky; top: 24px; align-self: start; height: auto; display: flex; flex-direction: column; gap: 4px;
    background: transparent; border: 0; backdrop-filter: none; padding: 0;
  }
  .nav a { flex-direction: row; justify-content: flex-start; gap: 12px; font-size: 14px; padding: 10px 14px; border-radius: 14px; }
  .nav a[aria-current="page"] { background: var(--card); box-shadow: var(--shadow); }
  .nav a[aria-current="page"] .ni { background: transparent; padding: 0; }
  .two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
  .two-col > .card { margin: 7px 0; }
  .save-bar { bottom: 12px; }
  #toast { bottom: 32px; }
  .stats { grid-template-columns: repeat(4, 1fr); }
  .hero h1 { font-size: 30px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ==========================================================
   スマートフォン幅の調整（〜899px のみ。PCレイアウトには影響しない）
   ========================================================== */
@media (max-width: 899px) {
  /* 横スクロールの防止（fixed のナビは viewport 基準なので影響なし） */
  html, body { overflow-x: clip; max-width: 100%; }
  .shell { padding-left: max(14px, env(safe-area-inset-left)); padding-right: max(14px, env(safe-area-inset-right)); }
  main, .card, .chart-wrap, details, .field { min-width: 0; max-width: 100%; }
  svg, img { max-width: 100%; }

  /* グリッドの列を内容幅で押し広げない */
  .fc-grid, .mot-grid, .scale, .stats, .cal-grid { grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); }
  .fc-grid { --cols: 3; }
  .mot-grid, .scale { --cols: 6; }
  .stats { --cols: 2; }
  .cal-grid { --cols: 7; }
  .fc-grid > *, .mot-grid > *, .scale > *, .stats > * { min-width: 0; }
  .today-card { grid-template-columns: 80px minmax(0, 1fr); }
  .today-card .wx { width: 80px; height: 80px; }

  /* やる気ボタン：アイコンをボタン幅に合わせて縮める */
  .mot-grid { gap: 5px; }
  .mot { padding: 6px 0; }
  .mot .wx { width: 100%; max-width: 38px; height: auto; aspect-ratio: 1; }

  /* 予報カード */
  .fc-grid { gap: 6px; }
  .fc { padding: 10px 4px 12px; }
  .fc .d { line-height: 1.5; }
  .fc .lbl { font-size: 12px; letter-spacing: -0.02em; }
  .fc .rel { padding: 0 6px; }

  /* 入力・ボタン */
  select, input[type="text"], textarea, input[type="date"] { max-width: 100%; font-size: 16px; } /* iOSの自動ズーム防止 */
  .sleep-row select { min-width: 72px; }
  .btn-row .btn { max-width: 100%; }
  .btn { white-space: normal; text-align: center; }
  .add-row input { min-width: 0; }
  .tagbtn, .taglist .t, .chip { max-width: 100%; overflow-wrap: anywhere; }
  .field > .lab { flex-wrap: wrap; }

  /* 表・グラフ */
  .cmp { table-layout: fixed; }
  .cmp td, .cmp th { overflow-wrap: anywhere; }
  .chart-tip { white-space: normal; max-width: 100%; }
  .bar-row { grid-template-columns: 4.2em minmax(0, 1fr) auto; }
  #demo-banner select { max-width: 60vw; }
}

/* 小さめのスマートフォン（〜374px） */
@media (max-width: 374px) {
  body { font-size: 14.5px; }
  .shell { padding-left: max(10px, env(safe-area-inset-left)); padding-right: max(10px, env(safe-area-inset-right)); }
  .card { padding: 14px 12px; }
  .hero h1 { font-size: 24px; }
  .fc-grid { gap: 4px; }
  .fc { padding: 8px 2px 10px; border-radius: 14px; }
  .fc .d { font-size: 11px; }
  .fc .wx { width: 44px; height: 44px; }
  .fc .lbl { font-size: 11px; letter-spacing: -0.04em; }
  .fc .rel { font-size: 10px; padding: 0 5px; }
  .mot-grid, .scale { gap: 4px; }
  .mot { border-radius: 12px; }
  .mot .num { font-size: 14px; }
  .date-bar .dlabel { font-size: 14.5px; }
  .icon-btn { width: 36px; height: 36px; flex: none; }
  .today-card { grid-template-columns: 64px minmax(0, 1fr); gap: 10px; }
  .today-card .wx { width: 64px; height: 64px; }
  .stat { padding: 8px 10px; }
  .stat .v { font-size: 18px; }
  .nav a { font-size: 10.5px; }
  .nav a[aria-current="page"] .ni { padding: 2px 10px; }
}
