* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, 'Hiragino Sans', sans-serif;
  background: #f7f4f0;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
header {
  padding: 12px 16px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
header h1 { font-size: .8rem; font-weight: 700; color: #888; letter-spacing:.06em; }
.date-badge {
  font-size: .75rem; font-weight: 700; color: #666;
  background: #ede9e4; border-radius: 20px; padding: 3px 10px;
}
.tabs {
  display: flex; gap: 6px; padding: 0 16px 10px; flex-shrink: 0;
}
.tab {
  flex: 1; text-align: center; font-size: .75rem; font-weight: 700;
  padding: 6px 0; border-radius: 12px; cursor: pointer;
  color: #aaa; background: #ede9e4; border: none;
  font-family: inherit; transition: background .12s, color .12s;
}
.tab.active { background: #4a4a4a; color: #fff; }

#view-today {
  flex: 1; display: grid; grid-template-columns: 1fr 1fr;
  gap: 10px; padding: 0 12px 14px; overflow: hidden;
}
.card {
  border-radius: 20px; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 4px; position: relative; padding: 16px 10px 14px;
  user-select: none;
}
.card .label { font-size: .75rem; font-weight: 600; opacity: .7; text-align: center; line-height: 1.4; }
.card .count { font-size: 3.4rem; font-weight: 800; line-height: 1; letter-spacing: -.02em; }
.card .unit  { font-size: .68rem; opacity: .55; }
.btn-row { display: flex; gap: 10px; margin-top: 6px; }
.btn {
  width: 44px; height: 44px; border-radius: 50%; border: none;
  font-size: 1.4rem; font-weight: 800; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-family: inherit; transition: transform .08s, filter .08s;
  -webkit-tap-highlight-color: transparent; line-height: 1;
}
.btn:active { transform: scale(.88); filter: brightness(.88); }
.btn-plus  { background: rgba(0,0,0,.13); color: inherit; }
.btn-minus { background: rgba(0,0,0,.07); color: inherit; opacity: .7; }
.btn-minus:disabled { opacity: .2; cursor: default; }
.flash {
  position: absolute; font-size: 1rem; font-weight: 800;
  opacity: 0; pointer-events: none;
  animation: floatUp .5s ease-out forwards;
  top: 30%; left: 50%; transform: translateX(-50%);
}
@keyframes floatUp {
  0%   { opacity: .85; transform: translateX(-50%) translateY(0); }
  100% { opacity: 0;   transform: translateX(-50%) translateY(-36px); }
}
.c0 { background: #fce4ec; color: #c2476a; }
.c1 { background: #e3f2fd; color: #2979b0; }
.c2 { background: #e8f5e9; color: #2e7d52; }
.c3 { background: #fff3e0; color: #b85c2a; }

#view-history {
  flex: 1; overflow-y: auto; padding: 0 12px 16px;
  display: none; flex-direction: column; gap: 10px;
}
#view-history.show { display: flex; }
.hist-card {
  background: #fff; border-radius: 16px; padding: 12px 16px;
  box-shadow: 0 1px 6px rgba(0,0,0,.06);
}
.hist-date { font-size: .75rem; font-weight: 700; color: #888; margin-bottom: 8px; }
.hist-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 3px 0; font-size: .82rem; color: #444;
  border-bottom: 1px solid #f0f0f0;
}
.hist-row:last-child { border-bottom: none; }
.hist-val { font-weight: 800; font-size: .95rem; }
.no-history { text-align: center; color: #bbb; font-size: .82rem; padding-top: 40px; }

.hist-pager {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  padding: 6px 0 10px; flex-shrink: 0;
}
.hist-pager button {
  background: #ede9e4; border: none; border-radius: 50%; width: 32px; height: 32px;
  font-size: .85rem; font-weight: 700; color: #888; cursor: pointer;
  display: flex; align-items: center; justify-content: center; font-family: inherit;
}
.hist-pager button:disabled { opacity: .25; cursor: default; }
.hist-pager button:active:not(:disabled) { background: #ddd; }
.hist-pager .hist-month { font-size: .8rem; font-weight: 700; color: #666; min-width: 90px; text-align: center; }

.footer {
  padding: 6px 16px 10px; flex-shrink: 0;
  display: flex; justify-content: flex-end; gap: 8px;
}
.footer-btn {
  font-size: .7rem; background: none;
  border: 1px solid #ddd; border-radius: 20px; padding: 4px 12px;
  cursor: pointer; font-family: inherit;
}
.footer-btn:active { background: #eee; }
.reset-btn { color: #bbb; }
.export-btn { color: #888; }
.import-btn { color: #6a9fd8; border-color: #b8d0e8; }

/* ── 履歴編集ボタン ── */
.hist-date-row {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px;
}
.hist-edit-btn {
  font-size: .68rem; color: #aaa; background: none;
  border: 1px solid #ddd; border-radius: 12px; padding: 2px 10px;
  cursor: pointer; font-family: inherit;
}
.hist-edit-btn:active { background: #f0f0f0; }

/* ── 編集モーダル ── */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.35); z-index: 100;
  align-items: flex-end; justify-content: center;
}
.modal-overlay.show { display: flex; }
.modal-box {
  background: #fff; border-radius: 24px 24px 0 0;
  padding: 24px 20px 32px; width: 100%; max-width: 480px;
}
.modal-title {
  font-size: .8rem; font-weight: 700; color: #888;
  text-align: center; margin-bottom: 18px;
}
.modal-field {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 0; border-bottom: 1px solid #f0f0f0;
}
.modal-field:last-of-type { border-bottom: none; }
.modal-field label { font-size: .85rem; color: #444; }
.modal-counter {
  display: flex; align-items: center; gap: 8px;
}
.modal-counter button {
  width: 32px; height: 32px; border-radius: 50%; border: none;
  background: #ede9e4; font-size: 1.1rem; font-weight: 800;
  cursor: pointer; font-family: inherit; color: #666;
  display: flex; align-items: center; justify-content: center;
}
.modal-counter button:active { background: #ddd; }
.modal-counter input {
  width: 48px; text-align: center; font-size: 1.1rem; font-weight: 800;
  border: none; background: none; font-family: inherit; color: #333;
}
.modal-counter input::-webkit-inner-spin-button { -webkit-appearance: none; }
.modal-actions {
  display: flex; gap: 10px; margin-top: 20px;
}
.modal-btn {
  flex: 1; padding: 12px; border-radius: 14px; border: none;
  font-size: .85rem; font-weight: 700; cursor: pointer; font-family: inherit;
}
.modal-cancel { background: #ede9e4; color: #888; }
.modal-save   { background: #4a4a4a; color: #fff; }
.modal-cancel:active { background: #ddd; }
.modal-save:active   { background: #333; }

/* ── 統計タブ ── */
#view-stats {
  flex: 1; overflow-y: auto; padding: 0 12px 16px;
  display: none; flex-direction: column; gap: 14px;
}
#view-stats.show { display: flex; }
.stats-section {
  background: #fff; border-radius: 16px; padding: 14px 14px 12px;
  box-shadow: 0 1px 6px rgba(0,0,0,.06);
}
.stats-title {
  font-size: .72rem; font-weight: 700; color: #aaa;
  letter-spacing: .06em; margin-bottom: 10px;
}
.heatmap-wrapper { overflow-x: auto; position: relative; }
.heat-tip {
  font-size: .72rem; color: #555; background: #f4f0ec;
  border-radius: 8px; padding: 4px 10px;
  margin-top: 6px; text-align: center;
  opacity: 0; transition: opacity .2s;
  min-height: 22px;
}
.graph-wrapper { overflow: hidden; }

/* ── 今月の合計 ── */
.month-summary { display: flex; flex-direction: column; gap: 8px; }
.summary-row {
  display: flex; align-items: center; gap: 8px;
}
.summary-label { font-size: .78rem; color: #666; width: 100px; flex-shrink: 0; }
.summary-bar-wrap {
  flex: 1; height: 8px; background: #f0f0f0; border-radius: 4px; overflow: hidden;
}
.summary-bar {
  height: 100%; border-radius: 4px; min-width: 4px;
  transition: width .3s ease;
}
.summary-bar.c0 { background: #c2476a; }
.summary-bar.c1 { background: #2979b0; }
.summary-bar.c2 { background: #2e7d52; }
.summary-bar.c3 { background: #b85c2a; }
.summary-val { font-size: .8rem; font-weight: 800; color: #444; width: 28px; text-align: right; flex-shrink: 0; }
.import-btn { color: #6a9fd8; border-color: #b8d0e8; }

/* PWA install banner */
#install-banner {
  display: none;
  margin: 0 12px 8px;
  background: #4a4a4a;
  color: #fff;
  border-radius: 14px;
  padding: 10px 14px;
  font-size: .75rem;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
#install-banner.show { display: flex; }
#install-banner span { flex: 1; line-height: 1.4; }
#install-btn {
  background: #fff; color: #4a4a4a; border: none;
  border-radius: 10px; font-size: .72rem; font-weight: 700;
  padding: 6px 12px; cursor: pointer; font-family: inherit;
  white-space: nowrap;
}
#banner-close {
  background: none; border: none; color: rgba(255,255,255,.5);
  font-size: 1rem; cursor: pointer; padding: 0 2px;
}
