/* ===========================
   Reset & Variables
   =========================== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --c1: #def2d9;
  --c2: #e2daf2;
  --c3: #fce2d4;
  --c4: #d9ebf2;
  --c5: #f2d9de;

  --ink:       #2a2228;
  --ink-mid:   #7a6e76;
  --ink-light: #c0b4bc;
  --bg:        #fdf9f7;
  --white:     #ffffff;

  --milk:   #fce2d4;
  --pee:    #d9ebf2;
  --poop:   #c9a580;
  --sleep:  #e2daf2;
  --weight: #f2d9de;
  --vitamin: #def2d9;

  --radius-card: 20px;
  --radius-btn:  14px;

  --shadow-card: 0 2px 10px rgba(42,34,40,.06);
  --shadow-btn:  0 2px 8px rgba(42,34,40,.08);

  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left:   env(safe-area-inset-left, 0px);
  --safe-right:  env(safe-area-inset-right, 0px);
}

/* ===========================
   Base
   =========================== */
html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100%;
  padding-top: var(--safe-top);
  padding-bottom: calc(var(--safe-bottom) + 20px);
  padding-left:  var(--safe-left);
  padding-right: var(--safe-right);
}

/* ===========================
   Header
   =========================== */
.app-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 24px 18px 0;
  max-width: 540px;
  margin: 0 auto;
}

.app-title {
  font-family: 'DM Serif Display', serif;
  font-size: clamp(20px, 5vw, 24px);
  font-weight: 400;
  letter-spacing: -0.3px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.calendar-btn {
  font-family: 'DM Sans', sans-serif;
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-mid);
  background: var(--white);
  border: 1px solid rgba(0,0,0,.08);
  border-radius: 20px;
  padding: 6px 14px;
  cursor: pointer;
  touch-action: manipulation;
  transition: all 0.15s;
  letter-spacing: 0.3px;
}

.calendar-btn:active {
  background: var(--c4);
  border-color: var(--c4);
  color: var(--ink);
}

.today-btn {
  font-family: 'DM Sans', sans-serif;
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-mid);
  background: var(--white);
  border: 1px solid rgba(0,0,0,.08);
  border-radius: 20px;
  padding: 6px 14px;
  cursor: pointer;
  touch-action: manipulation;
  transition: all 0.15s;
  letter-spacing: 0.3px;
}

.today-btn:active {
  background: var(--c4);
  border-color: var(--c4);
  color: var(--ink);
}

/* ===========================
   Date Navigation
   =========================== */
.date-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 540px;
  margin: 16px auto 0;
  padding: 0 18px;
}

.nav-btn {
  width: 40px;
  height: 40px;
  border: none;
  background: var(--white);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  touch-action: manipulation;
  flex-shrink: 0;
  color: var(--ink);
  box-shadow: var(--shadow-btn);
  transition: all 0.15s;
}

.nav-btn:active {
  transform: scale(0.94);
  background: var(--c4);
}

.nav-btn:disabled {
  opacity: 0.3;
  pointer-events: none;
}

.date-display {
  flex: 1;
  text-align: center;
  font-size: 15px;
  font-weight: 500;
  letter-spacing: -0.2px;
  color: var(--ink);
}

/* ===========================
   Main Layout
   =========================== */
.app-main {
  max-width: 540px;
  margin: 0 auto;
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ===========================
   Quick Actions
   =========================== */
.quick-actions {
  background: var(--white);
  border-radius: var(--radius-card);
  padding: 20px 18px;
  box-shadow: var(--shadow-card);
}

.qa-title {
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-mid);
  letter-spacing: 1.3px;
  text-transform: uppercase;
  margin-bottom: 14px;
}

.action-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.action-btn {
  aspect-ratio: 1;
  border: none;
  border-radius: var(--radius-btn);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  touch-action: manipulation;
  position: relative;
  padding: 12px 8px;
  transition: all 0.2s;
  box-shadow: var(--shadow-btn);
}

.action-btn:active {
  transform: scale(0.95);
}

.btn-milk   { background: var(--milk);   color: #c27c5a; }
.btn-pee    { background: var(--pee);    color: #3a7ca5; }
.btn-poop   { background: var(--poop);   color: #6b5432; }
.btn-sleep  { background: var(--sleep);  color: #7c5cbf; }
.btn-weight { background: var(--weight); color: #c75b6d; }
.btn-vitamin{ background: var(--vitamin); color: #5a8c5a; }

.action-icon {
  flex-shrink: 0;
}

.action-label {
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.2px;
}

.action-count,
.action-latest {
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 10px;
  font-weight: 600;
  background: rgba(0,0,0,.1);
  color: inherit;
  border-radius: 10px;
  padding: 2px 7px;
  line-height: 1.4;
  min-width: 20px;
  text-align: center;
}

.action-latest {
  font-size: 9px;
  padding: 2px 5px;
}

.action-status {
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 16px;
  background: transparent;
  padding: 0;
  min-width: auto;
}

.sleep-indicator {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: transparent;
  opacity: 0;
  transition: opacity 0.3s;
}

.sleep-indicator.active {
  opacity: 1;
  background: #7c5cbf;
  animation: sleepBlink 2s ease-in-out infinite;
}

@keyframes sleepBlink {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.3; transform: scale(0.85); }
}

.btn-sleep.sleeping {
  background: #b8a3d9;
}

.btn-vitamin.taken {
  opacity: 0.6;
}

/* ===========================
   Summary Section
   =========================== */
.summary-section {}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.summary-card {
  border-radius: var(--radius-btn);
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.card-sleep { background: var(--c2); }
.card-avg   { background: var(--c1); }
.card-next  { background: var(--c4); }

.sc-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: rgba(255,255,255,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 2px;
}

.card-sleep .sc-icon { color: #7c5cbf; }
.card-avg .sc-icon   { color: #5a8c5a; }
.card-next .sc-icon  { color: #3a7ca5; }

.sc-label {
  font-size: 10px;
  font-weight: 500;
  color: var(--ink-mid);
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.sc-value {
  font-family: 'DM Serif Display', serif;
  font-size: 20px;
  letter-spacing: -0.5px;
  color: var(--ink);
  line-height: 1.1;
}

/* ===========================
   Timeline
   =========================== */
.timeline-section {
  background: var(--white);
  border-radius: var(--radius-card);
  padding: 20px 18px;
  box-shadow: var(--shadow-card);
}

.timeline-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.timeline-title {
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-mid);
  letter-spacing: 1.3px;
  text-transform: uppercase;
}

.clear-day-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  background: none;
  border: none;
  font-family: 'DM Sans', sans-serif;
  font-size: 12px;
  color: var(--ink-mid);
  cursor: pointer;
  touch-action: manipulation;
  padding: 6px 10px;
  border-radius: 8px;
  transition: all 0.15s;
}

.clear-day-btn:active {
  background: var(--c5);
  color: var(--ink);
}

.timeline-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.timeline-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 32px 20px;
  color: var(--ink-light);
  font-size: 13px;
}

.timeline-empty svg {
  opacity: 0.3;
}

/* Timeline Item */
.timeline-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--bg);
  border-radius: 12px;
  animation: slideIn 0.2s ease;
  position: relative;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.tl-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.tl-icon svg {
  width: 20px;
  height: 20px;
}

.tl-milk   .tl-icon { background: var(--milk);   color: #c27c5a; }
.tl-pee    .tl-icon { background: var(--pee);    color: #3a7ca5; }
.tl-poop   .tl-icon { background: var(--poop);   color: #6b5432; }
.tl-sleep  .tl-icon { background: var(--sleep);  color: #7c5cbf; }
.tl-wake   .tl-icon { background: #fef3e8;       color: #e89b3c; }
.tl-weight .tl-icon { background: var(--weight); color: #c75b6d; }
.tl-vitamin .tl-icon{ background: var(--vitamin); color: #5a8c5a; }

.tl-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.tl-type {
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
  letter-spacing: -0.1px;
}

.tl-detail {
  font-size: 12px;
  color: var(--ink-mid);
}

.tl-time {
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-mid);
  letter-spacing: -0.2px;
  flex-shrink: 0;
}

.tl-delete {
  position: absolute;
  top: 50%;                    /* 変更: 8px → 50% */
  transform: translateY(-50%); /* 追加: 垂直中央揃え */
  right: 8px;
  width: 24px;
  height: 24px;
  border: none;
  background: rgba(0,0,0,.05);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
  color: var(--ink-mid);
}

.tl-delete svg {  /* 追加 */
  display: block;
}

.timeline-item:hover .tl-delete,
.timeline-item:active .tl-delete {
  opacity: 1;
}

.tl-delete:active {
  background: rgba(0,0,0,.15);
}

/* ===========================
   Responsive
   =========================== */
@media (max-width: 360px) {
  .action-grid {
    gap: 8px;
  }

  .action-btn {
    padding: 10px 6px;
  }

  .action-label {
    font-size: 11px;
  }
}

@media (min-width: 541px) {
  .app-header,
  .date-nav,
  .app-main {
    max-width: 540px;
  }
}

/* ===========================
   Calendar Modal
   =========================== */
.calendar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
  backdrop-filter: blur(2px);
}

.calendar-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.calendar-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.9);
  width: calc(100% - 32px);
  max-width: 400px;
  background: var(--white);
  border-radius: var(--radius-card);
  box-shadow: 0 10px 40px rgba(0,0,0,0.15);
  z-index: 101;
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s;
  padding: 20px;
  max-height: calc(100vh - 80px);
  overflow-y: auto;
}

.calendar-modal.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, -50%) scale(1);
}

.calendar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.cal-nav-btn {
  width: 32px;
  height: 32px;
  border: none;
  background: var(--bg);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--ink);
  transition: all 0.15s;
}

.cal-nav-btn:active {
  background: var(--c4);
}

.cal-month-year {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.2px;
}

/* Month Summary */
.month-summary {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.ms-item {
  flex: 1;
  background: var(--bg);
  border-radius: 12px;
  padding: 10px;
  text-align: center;
}

.ms-label {
  font-size: 9px;
  font-weight: 500;
  color: var(--ink-mid);
  letter-spacing: 0.5px;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.ms-value {
  font-family: 'DM Serif Display', serif;
  font-size: 18px;
  letter-spacing: -0.5px;
  color: var(--ink);
}

/* Calendar Grid */
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.cal-day-label {
  text-align: center;
  font-size: 10px;
  font-weight: 500;
  color: var(--ink-mid);
  padding: 6px 0;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

.cal-day {
  aspect-ratio: 1;
  border: none;
  background: transparent;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  cursor: pointer;
  color: var(--ink);
  position: relative;
  transition: all 0.15s;
}

.cal-day:hover:not(.empty):not(.disabled) {
  background: var(--bg);
}

.cal-day:active:not(.empty):not(.disabled) {
  background: var(--c4);
}

.cal-day.empty {
  opacity: 0;
  pointer-events: none;
}

.cal-day.disabled {
  color: var(--ink-light);
  pointer-events: none;
}

.cal-day.today {
  background: var(--c4);
  font-weight: 600;
}

.cal-day.selected {
  background: var(--ink);
  color: var(--white);
  font-weight: 600;
}

.cal-day.has-data::after {
  content: '';
  position: absolute;
  bottom: 3px;
  left: 50%;
  transform: translateX(-50%);
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--active);
}

.cal-day.selected.has-data::after {
  background: var(--white);
}

