:root {
  --navy: #0a1f44;      /* ベース */
  --navy-2: #12295a;    /* カード・バー */
  --navy-3: #1c3a78;    /* 入力欄・区切り */
  --accent: #38bdf8;    /* 強調(水色) */
  --accent-soft: rgba(56, 189, 248, .18);
  --text: #fff;
  --sub: #9db4d8;
  --line: #27447f;
  --tab-h: 58px;
}
/* 連続タップでの拡大(ダブルタップズーム)を無効にする */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
html, body { height: 100%; margin: 0; background: var(--navy); color: var(--text); overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", sans-serif; }
/* 表示領域の外(ホームインジケータ側)に見える色。下メニューと同じ色にして、メニューが画面の下端まで続いて見えるようにする */
html { background: var(--navy-2); }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
input, select { font: inherit; color: inherit; }
h3 { margin: 22px 16px 8px; font-size: 17px; }
a { color: var(--accent); }

/* 画面全体を固定し、中身だけスクロールさせる(下メニューがずれないように) */
#shell { position: fixed; inset: 0; overflow: hidden; display: flex; flex-direction: column; background: var(--navy); }
#app { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; overscroll-behavior: none;
  padding-bottom: 24px; width: 100%; max-width: 640px; margin: 0 auto; }
/* 下の余白(ホームインジケータ分)は各ボタンの中に持たせ、選択色が画面の下端まで届くようにする */
#tabs { flex: none; display: flex; background: var(--navy-2); border-top: 1px solid var(--line); }
#tabs:empty { display: none; }
#app::-webkit-scrollbar, .chips::-webkit-scrollbar { display: none; }
.chips { scrollbar-width: none; }
#tabs a { flex: 1; text-align: center; padding: 8px 0 calc(4px + env(safe-area-inset-bottom) * 0.35); font-size: 11px; color: #fff; opacity: .6; text-decoration: none; }
#tabs a svg { display: block; width: 24px; height: 24px; margin: 0 auto 3px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
#tabs a.on { opacity: 1; background: var(--accent-soft); }

.header { background: var(--navy-2); color: #fff; padding: calc(env(safe-area-inset-top) + 12px) 14px 14px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 56px; }
.header h1 { margin: 0; font-size: 18px; font-weight: 700; text-align: center; flex: 1; }
.header .ib { width: 40px; height: 36px; font-size: 22px; color: var(--accent); text-align: center; }
.header .sp { width: 40px; }

.card { background: var(--navy-2); border-radius: 14px; margin: 12px 12px 0; overflow: hidden; }
.card-head { background: var(--accent); color: var(--navy); padding: 10px 14px; display: flex; align-items: center;
  justify-content: space-between; gap: 8px; font-weight: 700; }
.card-head .meta { font-size: 12px; font-weight: 600; text-align: right; }
.card-head button { color: var(--navy); font-size: 22px; padding: 0 8px; }
.card-body { padding: 4px 0 10px; }

.btn { display: block; width: calc(100% - 24px); margin: 12px; padding: 14px; border-radius: 12px;
  background: var(--accent); color: var(--navy); font-weight: 700; text-align: center; font-size: 16px; }
.btn.ghost { background: transparent; color: var(--accent); border: 2px solid var(--accent); }
.btn.small { width: auto; display: inline-block; margin: 0; padding: 10px 18px; font-size: 15px; }
.btn.gray { background: var(--navy-3); color: #fff; border: 1px solid var(--line); }
.row2 { display: flex; gap: 0; }
.row2 .btn { flex: 1; }

/* calendar: 横スワイプはJSで処理する。スライドのはみ出しは切り取り、横スクロールさせない */
[data-swipe] { touch-action: pan-y; overflow: hidden; }
/* calendar */
.cal { background: var(--navy-2); margin: 12px; border-radius: 14px; padding: 10px 6px 12px; }
.cal.on-hero { background: transparent; margin: 0; padding: 6px 12px 12px; }
.cal-title { display: flex; align-items: center; justify-content: space-between; padding: 0 12px 6px;
  color: var(--accent); font-size: 18px; font-weight: 600; }
.cal.on-hero .cal-title { color: #fff; font-size: 20px; font-weight: 700; padding-bottom: 2px; }
.cal.on-hero .cal-title button { color: var(--accent); }
.cal.on-hero .cal-grid .d { width: 36px; height: 36px; line-height: 34px; }
.cal.on-hero .cal-grid { row-gap: 4px; }
.cal-title button { font-size: 20px; color: var(--accent); padding: 0 12px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; row-gap: 6px; }
.cal-grid .dow { font-size: 13px; color: var(--accent); padding: 4px 0; }
.cal-grid .d { width: 38px; height: 38px; line-height: 38px; margin: 0 auto; border-radius: 50%; font-size: 16px; color: #fff; }
.cal-grid .d.out { color: var(--sub); opacity: .55; }
.cal.on-hero .d { border: 1px solid var(--line); }
.cal.on-hero .d.out { border-color: transparent; }
.cal-grid .d.mark { background: var(--accent); color: var(--navy); font-weight: 700; border-color: var(--accent); opacity: 1; }
.cal-grid .d.today { outline: 2px solid #fff; outline-offset: 1px; }

/* home stats */
.hero { background: var(--navy-2); padding-top: calc(env(safe-area-inset-top) + 10px); }
.stats2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 0 12px 14px; }
.stats2 .stat .big { font-size: 26px; }
.stats { display: grid; gap: 10px; padding: 0 12px 14px; }
.stat { background: var(--navy-2); border: 1px solid var(--line); border-radius: 14px; padding: 10px 14px; color: #fff; }
.stat .label { font-size: 12px; font-weight: 600; color: var(--sub); }
.stat .big { font-size: 30px; font-weight: 800; }
.weeks { display: grid; grid-template-columns: 40px 1fr; gap: 4px 8px; font-size: 12px; margin-top: 6px; align-items: center; color: var(--sub); }
.weeks i { display: block; height: 14px; background: var(--accent); border-radius: 2px; min-width: 2px; }
.archive { display: flex; justify-content: space-between; align-items: center; padding: 6px 14px 14px; color: #fff; font-weight: 800; }
.archive .n { font-size: 40px; line-height: 1; color: var(--accent); }
.archive small { font-size: 14px; }
.archive .tot { background: var(--accent); color: var(--navy); border-radius: 4px; padding: 2px 8px; font-size: 15px; }

/* day / sets */
.summary { background: var(--navy-2); display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; padding: 0 12px 14px; }
.summary div { border: 1px solid var(--accent); border-radius: 14px; color: var(--sub); padding: 8px 2px; text-align: center; font-size: 11px; font-weight: 700; }
.summary b { display: block; font-size: 22px; color: #fff; }
.sh { display: grid; grid-template-columns: 46px 1fr 1fr 70px 30px; padding: 6px 14px 2px; font-size: 12px; color: var(--sub); }
.srow { display: grid; grid-template-columns: 34px 1fr 1fr 70px 30px; align-items: center; padding: 8px 14px 6px;
  border-top: 1px solid var(--line); font-size: 18px; }
.srow .w b, .srow .r b { font-size: 24px; }
.srow .w small, .srow .r small { font-size: 13px; color: var(--sub); }
.srow .rm { font-size: 14px; color: var(--accent); }
.srow .note { grid-column: 1 / -1; text-align: center; color: var(--sub); font-size: 17px; padding-top: 2px; }
.srow button { color: var(--sub); font-size: 20px; }
.addset { display: block; margin: 8px auto 0; width: 40px; height: 40px; border-radius: 50%; background: var(--navy-3); color: var(--accent); font-size: 26px; }

/* input screen */
.last { background: var(--navy-3); margin: 12px; border-radius: 16px; padding: 12px 16px; display: flex; justify-content: space-between; gap: 8px; }
.last .t { font-size: 16px; }
.last .t a { margin-left: 12px; }
.last table { margin-top: 6px; font-size: 16px; border-collapse: collapse; }
.last td { padding: 1px 14px 1px 0; }
.last .copy { width: 44px; height: 44px; font-size: 26px; align-self: flex-start; }
.iset { background: var(--navy-2); margin: 0 12px; border-top: 1px solid var(--line); padding: 10px 12px 8px; }
.iset:first-of-type { border-top: 0; }
.iset .l1 { display: grid; grid-template-columns: 24px 1fr 1fr; gap: 8px; align-items: center; }
.iset .l2 { display: grid; grid-template-columns: 1fr 70px 30px; gap: 8px; align-items: center; margin-top: 6px; }
.stp { display: flex; align-items: center; gap: 4px; }
.stp button { width: 34px; height: 34px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-size: 20px; font-weight: 700; flex: none; }
.stp input { min-width: 0; width: 100%; border: 0; border-bottom: 1px solid var(--accent); text-align: center; font-size: 22px; font-weight: 700; padding: 2px 0; background: transparent; border-radius: 0; }
.stp u { text-decoration: none; font-size: 13px; color: var(--sub); flex: none; }
.iset .note { border: 0; border-bottom: 1px solid var(--line); text-align: center; font-size: 16px; padding: 4px 0; background: transparent; border-radius: 0; width: 100%; }
.iset .note::placeholder { color: var(--sub); }
.iset .rm { color: var(--accent); font-size: 14px; text-align: right; }
.iset .no { font-size: 20px; }
.iset .del { color: var(--sub); font-size: 20px; }
.iwrap-card { background: var(--navy-2); margin: 0 12px; border-radius: 14px; overflow: hidden; }
.iwrap-card .iset { margin: 0; }

/* 画面・月・シートの切り替えアニメーション */
@keyframes goNext { from { opacity: 0; transform: translateX(36px); } to { opacity: 1; transform: none; } }
@keyframes goPrev { from { opacity: 0; transform: translateX(-36px); } to { opacity: 1; transform: none; } }
@keyframes goFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes calNext { from { opacity: 0; transform: translateX(44px); } to { opacity: 1; transform: none; } }
@keyframes calPrev { from { opacity: 0; transform: translateX(-44px); } to { opacity: 1; transform: none; } }
@keyframes sheetUp { from { opacity: 0; transform: translateY(48px); } to { opacity: 1; transform: none; } }
.go-next { animation: goNext .45s cubic-bezier(.22, .8, .25, 1); }
.go-prev { animation: goPrev .45s cubic-bezier(.22, .8, .25, 1); }
.go-fade { animation: goFade .35s ease-out; }
.cal-next { animation: calNext .42s cubic-bezier(.22, .8, .25, 1); }
.cal-prev { animation: calPrev .42s cubic-bezier(.22, .8, .25, 1); }
#modal.open { animation: goFade .3s ease-out; }
#modal.open .sheet { animation: sheetUp .4s cubic-bezier(.22, .8, .25, 1); }
#tabs a { transition: opacity .3s, background-color .3s; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* 白い線アイコン */
.ic { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; vertical-align: middle; }
.header .ib { color: #fff; display: flex; align-items: center; justify-content: center; }
.card-head button { display: flex; align-items: center; }
.srow button, .iset .del, .trash, .last .copy { color: #fff; display: inline-flex; align-items: center; justify-content: center; }
.last .copy { width: 44px; height: 44px; }
.last .copy .ic { width: 26px; height: 26px; }
.sheet h2 .ic { margin-right: 4px; color: var(--accent); }

/* グラフの期間・単位 */
.rangebar { display: flex; gap: 6px; margin: 14px 12px 0; overflow-x: auto; scrollbar-width: none; }
.rangebar::-webkit-scrollbar { display: none; }
.rangebar button { flex: 1 0 auto; padding: 8px 12px; border-radius: 16px; background: var(--navy-3); color: var(--sub); font-size: 14px; white-space: nowrap; }
.rangebar button.on { background: var(--accent); color: var(--navy); font-weight: 700; }
.unit { color: var(--accent); font-size: 14px; font-weight: 600; }

.bwrow { cursor: pointer; }
.bwrow .r { display: flex; align-items: center; gap: 8px; }

/* lists */
.list { background: var(--navy-2); margin: 8px 12px 0; border-radius: 14px; overflow: hidden; }
.list > a, .list > div, .list > button { display: flex; width: 100%; justify-content: space-between; align-items: center;
  padding: 14px 16px; border-top: 1px solid var(--line); text-decoration: none; color: inherit; text-align: left; font-size: 16px; }
.list > :first-child { border-top: 0; }
.list .sub { color: var(--sub); font-size: 13px; }
.chips { display: flex; overflow-x: auto; background: var(--navy-2); border-bottom: 2px solid var(--accent); }
.chips button { flex: none; padding: 12px 14px; color: var(--accent); font-size: 15px; border-right: 1px solid var(--line); }
.chips button.on { background: var(--accent); color: var(--navy); font-weight: 700; }
.chips.sub { background: var(--navy); border-bottom: 1px solid var(--line); }
.chips.sub button { padding: 10px 14px; font-size: 14px; }
.linkbtn { color: var(--accent); text-decoration: underline; margin-left: 12px; font-size: 16px; }
.seg.three { width: 300px; }
.seg { display: flex; width: 220px; margin: 14px auto 0; background: var(--navy-3); border-radius: 10px; padding: 3px; }
.seg button { flex: 1; padding: 8px; border-radius: 8px; font-size: 15px; color: var(--sub); }
.seg button.on { background: var(--accent); color: var(--navy); font-weight: 700; }
.chartbox { background: var(--navy-2); margin: 0 12px; border-radius: 14px; padding: 10px 8px 6px; height: 240px; }
.empty { text-align: center; color: var(--sub); padding: 40px 16px; }

.form { background: var(--navy-2); margin: 12px; border-radius: 14px; padding: 14px; display: grid; gap: 10px; }
.form label { font-size: 13px; color: var(--sub); display: grid; gap: 4px; }
.form input, .form select { padding: 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 16px; background: var(--navy-3); color: #fff; }
.login { max-width: 360px; margin: 14vh auto 0; }
.login h2 { text-align: center; color: var(--accent); }

/* modal */
#modal { position: fixed; inset: 0; display: none; background: rgba(0,0,0,.55); z-index: 30; align-items: flex-end; justify-content: center; }
#modal.open { display: flex; }
.sheet { background: var(--navy-2); color: #fff; width: 100%; max-width: 640px; max-height: 80vh; overflow-y: auto; border-radius: 18px 18px 0 0;
  padding: 16px 0 calc(env(safe-area-inset-bottom) + 16px); }
.sheet h2 { margin: 0 16px 8px; font-size: 18px; }
.sheet .list { margin: 8px 12px; background: var(--navy); }
.sheet .chips { background: var(--navy); }
.sheet .form { margin: 8px 12px; padding: 0; background: none; }
.pb { padding: 10px 16px; border-top: 1px solid var(--line); }
.pb b { font-size: 22px; color: var(--accent); }
.pb small { color: var(--sub); display: block; }

#toast { position: fixed; left: 50%; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 24px); transform: translateX(-50%);
  background: var(--accent); color: var(--navy); font-weight: 600;
  padding: 10px 16px; border-radius: 20px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 40; max-width: 90vw; }
#toast.show { opacity: .97; }
.banner { background: var(--accent-soft); color: var(--accent); font-size: 12px; padding: 6px 12px; text-align: center; }
