/* ─── Reset & Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary:        #0891B2;
  --primary-light:  #E0F7FA;
  --primary-dark:   #0E7490;
  --bg:             #F0F4F8;
  --surface:        #FFFFFF;
  --border:         #E2E8F0;
  --text:           #1E293B;
  --text-muted:     #64748B;
  --danger:         #EF4444;
  --danger-light:   #FEE2E2;
  --success:        #22C55E;
  --nav-h:          64px;
  --header-h:       56px;
  --radius:         12px;
  --radius-sm:      8px;
  --shadow:         0 1px 4px rgba(0,0,0,0.10), 0 0 1px rgba(0,0,0,0.06);
  --shadow-lg:      0 8px 24px rgba(0,0,0,0.14);
}

html, body {
  height: 100%;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Hiragino Sans', 'Hiragino Kaku Gothic ProN',
               'Noto Sans JP', 'Yu Gothic', sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  /* Prevent pull-to-refresh on iOS */
  overscroll-behavior: none;
}

button { cursor: pointer; border: none; background: none; font: inherit; color: inherit; }
img    { display: block; max-width: 100%; }
textarea { font: inherit; }

/* ─── Layout ───────────────────────────────────────────────────────────────── */

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  height: 100vh; /* fallback */
}

.screen {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

.screen.hidden { display: none !important; }

/* ─── Header ───────────────────────────────────────────────────────────────── */

.app-header {
  display: flex;
  align-items: center;
  gap: 8px;
  height: var(--header-h);
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: relative;
}

.app-header h1 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  flex: 1;
}

.back-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--primary);
  font-size: 15px;
  font-weight: 500;
  padding: 8px 0;
  min-height: 44px;
  min-width: 44px;
}

.count-badge {
  font-size: 13px;
  font-weight: 600;
  color: var(--primary);
  background: var(--primary-light);
  padding: 2px 10px;
  border-radius: 999px;
}

/* ─── Scrollable main area ─────────────────────────────────────────────────── */

.scroll-area {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  /* 100px = ナビ64px + iPhoneホームインジケーター最大34px + 余白 */
  padding: 12px 16px 100px;
}

/* ─── Empty state ──────────────────────────────────────────────────────────── */

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 40px 24px;
  text-align: center;
}

.empty-state .empty-icon {
  font-size: 52px;
  margin-bottom: 8px;
  opacity: 0.6;
}

.empty-state p:first-of-type {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.empty-state p {
  font-size: 14px;
  color: var(--text-muted);
}

.empty-state.hidden { display: none; }

/* ─── Meal card ────────────────────────────────────────────────────────────── */

.meal-list { display: flex; flex-direction: column; gap: 12px; }
.meal-list.hidden { display: none; }

.meal-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.meal-img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: var(--border);
}

.meal-body {
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.meal-time {
  font-size: 13px;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: 0.02em;
}

.meal-memo {
  font-size: 15px;
  color: var(--text);
  word-break: break-word;
  line-height: 1.45;
}

.meal-memo.no-memo {
  color: var(--text-muted);
  font-style: italic;
  font-size: 13px;
}

.meal-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.btn-sm {
  flex: 1;
  min-height: 40px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  padding: 0 12px;
  transition: opacity 0.15s;
}

.btn-sm:active { opacity: 0.7; }

.btn-edit {
  background: var(--primary-light);
  color: var(--primary-dark);
}

.btn-sm.danger {
  background: var(--danger-light);
  color: var(--danger);
}

/* ─── Bottom Navigation ────────────────────────────────────────────────────── */

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  /* height にセーフエリアを含め、ボタン領域(64px)とホームインジケーター領域を確保 */
  height: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  z-index: 50;
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 44px;
  padding: 4px 0;
  color: var(--text-muted);
  transition: color 0.15s;
}

.nav-btn.active {
  color: var(--primary);
}

.nav-icon {
  font-size: 22px;
  line-height: 1;
}

.nav-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

/* Centre capture button */
.nav-capture {
  flex: none;
  width: 64px;
  height: 64px;
  background: var(--primary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(8, 145, 178, 0.45);
  transform: translateY(-12px);
  color: #fff;
  transition: transform 0.15s, box-shadow 0.15s;
  position: relative;
  z-index: 1;
}

.nav-capture:active {
  transform: translateY(-12px) scale(0.93);
  box-shadow: 0 2px 6px rgba(8, 145, 178, 0.35);
}

.capture-icon {
  font-size: 32px;
  line-height: 1;
  font-weight: 300;
  color: #fff;
}

/* ─── Calendar ─────────────────────────────────────────────────────────────── */

.cal-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 4px 6px;
}

.cal-nav-btn {
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: var(--primary);
  border-radius: 50%;
  transition: background 0.15s;
}

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

#cal-title {
  font-size: 17px;
  font-weight: 700;
}

#calendar-grid { padding-bottom: 8px; }

.btn-delete-month {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 48px;
  margin-top: 20px;
  padding: 12px 16px;
  background: var(--danger-light);
  color: var(--danger);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  transition: background 0.15s;
}

.btn-delete-month:active { background: #FECACA; }

.cal-row {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
}

.cal-hd {
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  padding: 6px 0;
}

.cal-hd.sun { color: #EF4444; }
.cal-hd.sat { color: #3B82F6; }

.cal-cell {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2px 0 4px;
}

.cal-day {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 500;
  transition: background 0.15s;
  position: relative;
  z-index: 1;
}

.cal-day:active { background: var(--primary-light); }

.cal-cell.sun .cal-day { color: #EF4444; }
.cal-cell.sat .cal-day { color: #3B82F6; }

.cal-cell.cal-today .cal-day {
  background: var(--primary);
  color: #fff;
  font-weight: 700;
}

.cal-dot {
  display: block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success);
  margin-top: 2px;
}

/* ─── Modal base ───────────────────────────────────────────────────────────── */

.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: flex-end;
}

.modal.hidden { display: none !important; }

.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.48);
}

.modal-sheet {
  position: relative;
  z-index: 1;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-height: 92vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.modal-header {
  display: flex;
  align-items: center;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border);
  gap: 8px;
}

.modal-header h2 {
  flex: 1;
  font-size: 17px;
  font-weight: 700;
}

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* ─── Capture: choose step ─────────────────────────────────────────────────── */

.choose-btns {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 20px 16px 24px;
}

.choose-btn {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--bg);
  border-radius: var(--radius);
  padding: 16px;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  transition: background 0.15s;
  min-height: 60px;
}

.choose-btn:active { background: var(--primary-light); }

.choose-btn .btn-icon { font-size: 28px; }

/* ─── Capture: camera step ─────────────────────────────────────────────────── */

#step-cam {
  background: #000;
  border-radius: 20px 20px 0 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#step-cam.hidden { display: none !important; }

.cam-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 2;
  background: linear-gradient(to bottom, rgba(0,0,0,0.5), transparent);
}

.cam-btn-icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: #fff;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.cam-viewfinder {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  background: #111;
  overflow: hidden;
}

#cam-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.cam-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 16px 28px;
  background: #000;
  gap: 40px;
}

.shutter-btn {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 4px solid #fff;
  background: rgba(255,255,255,0.15);
  position: relative;
  flex-shrink: 0;
  transition: transform 0.1s;
}

.shutter-btn::after {
  content: '';
  position: absolute;
  inset: 5px;
  border-radius: 50%;
  background: #fff;
}

.shutter-btn:active { transform: scale(0.9); }

/* ─── Capture: memo step ───────────────────────────────────────────────────── */

.preview-wrap {
  background: var(--border);
  aspect-ratio: 4 / 3;
  overflow: hidden;
}

.preview-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.memo-wrap {
  padding: 14px 16px 0;
  position: relative;
}

.memo-wrap textarea {
  width: 100%;
  height: 88px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 15px;
  color: var(--text);
  resize: none;
  background: var(--bg);
  outline: none;
  transition: border-color 0.15s;
}

.memo-wrap textarea:focus { border-color: var(--primary); }

.memo-count {
  position: absolute;
  bottom: 6px;
  right: 22px;
  font-size: 11px;
  color: var(--text-muted);
}

.memo-actions {
  display: flex;
  gap: 10px;
  padding: 12px 16px 24px;
}

.btn-primary {
  flex: 2;
  min-height: 50px;
  background: var(--primary);
  color: #fff;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 700;
  transition: opacity 0.15s;
}

.btn-primary:disabled { opacity: 0.55; }
.btn-primary:active   { opacity: 0.85; }

.btn-secondary {
  flex: 1;
  min-height: 50px;
  background: var(--bg);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  transition: background 0.15s;
}

.btn-secondary:active { background: var(--border); }

/* ─── Delete confirm modal ─────────────────────────────────────────────────── */

.confirm-body {
  padding: 24px 20px 0;
  text-align: center;
}

.confirm-body p {
  font-size: 15px;
  color: var(--text-muted);
  margin-top: 6px;
  line-height: 1.5;
}

.confirm-actions {
  display: flex;
  gap: 10px;
  padding: 20px 16px 28px;
}

.btn-danger {
  flex: 2;
  min-height: 50px;
  background: var(--danger);
  color: #fff;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 700;
  transition: opacity 0.15s;
}

.btn-danger:active { opacity: 0.85; }

/* ─── Edit modal ───────────────────────────────────────────────────────────── */

.edit-memo-wrap {
  padding: 14px 16px 0;
  position: relative;
}

.edit-memo-wrap textarea {
  width: 100%;
  height: 100px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 15px;
  color: var(--text);
  resize: none;
  background: var(--bg);
  outline: none;
  transition: border-color 0.15s;
}

.edit-memo-wrap textarea:focus { border-color: var(--primary); }

/* ─── Storage warning toast ────────────────────────────────────────────────── */

#storage-warning {
  position: fixed;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + 12px);
  left: 50%;
  transform: translateX(-50%);
  background: #1E293B;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: 999px;
  z-index: 300;
  white-space: nowrap;
  box-shadow: var(--shadow-lg);
}

#storage-warning.hidden { display: none; }

/* ─── Misc ─────────────────────────────────────────────────────────────────── */

.hidden { display: none !important; }

/* Drag handle hint on modal */
.modal-sheet::before {
  content: '';
  display: block;
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 10px auto 4px;
}

/* Focus-visible outlines for accessibility */
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
