:root {
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --bg: #f4f5fb;
  --card: #ffffff;
  --text: #1f2430;
  --muted: #6b7280;
  --border: #e5e7eb;
  --green: #16a34a;
  --red: #dc2626;
  --amber: #d97706;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
}

.topbar {
  background: var(--primary);
  color: #fff;
  padding-top: env(safe-area-inset-top);
  position: sticky; top: 0; z-index: 10;
}
.topbar-inner {
  max-width: 640px; margin: 0 auto;
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 16px;
}
.brand { font-weight: 700; }
.date-label { font-size: 13px; opacity: .9; }

.container { max-width: 640px; margin: 0 auto; padding: 12px 12px 24px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  margin: 10px 0;
}

h2 { font-size: 17px; margin: 18px 0 6px; }
h3 { font-size: 15px; margin: 4px 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }

.section-head { display: flex; justify-content: space-between; align-items: center; margin-top: 18px; }
.section-head h2 { margin: 0; }

.flash {
  max-width: 640px; margin: 10px auto 0; padding: 10px 14px;
  border-radius: 10px; font-size: 14px;
  background: #dcfce7; color: #166534;
}
.flash-error { background: #fee2e2; color: #991b1b; }

/* buttons / inputs */
.btn {
  display: inline-block; border: 1px solid var(--border);
  background: #fff; color: var(--text);
  border-radius: 10px; padding: 8px 14px; font-size: 14px;
  cursor: pointer; text-decoration: none; font-family: inherit;
}
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.btn-primary:active { background: var(--primary-dark); }
.btn-danger { background: #fff; color: var(--red); border-color: #fca5a5; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-block { width: 100%; margin-top: 10px; }
.input {
  width: 100%; padding: 9px 10px; border: 1px solid var(--border);
  border-radius: 10px; font-size: 15px; font-family: inherit; background: #fff;
}
.input-sm { padding: 6px 8px; font-size: 13px; width: auto; flex: 1; }
.w-auto { width: auto; flex: 0 0 auto; }

/* login */
.login-page { display: flex; align-items: center; min-height: 90vh; }
.login-card { width: 100%; max-width: 360px; margin: 0 auto; }
.login-title { font-size: 20px; text-align: center; }

/* tab bar */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  background: #fff; border-top: 1px solid var(--border);
  display: flex; justify-content: space-around;
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  flex: 1; text-align: center; padding: 8px 0 6px;
  font-size: 11px; color: var(--muted); text-decoration: none;
}
.tabbar a.on { color: var(--primary); font-weight: 700; }
.tabbar .ico { display: block; font-size: 20px; line-height: 1.2; }

/* today: plan card */
.plan-focus {
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  color: #fff; border: none;
}
.plan-focus h3 { color: #fff; margin-bottom: 4px; }
.plan-focus .focus-text { font-size: 16px; font-weight: 700; margin: 2px 0 8px; }
.plan-focus ul { margin: 6px 0 8px; padding-left: 20px; }
.plan-focus .btn { border: none; }

/* timeline */
.tl-item {
  display: flex; gap: 10px; padding: 8px 4px;
  border-bottom: 1px solid var(--border); align-items: flex-start;
}
.tl-item:last-child { border-bottom: none; }
.tl-time { flex: 0 0 88px; font-size: 12px; color: var(--muted); padding-top: 3px; white-space: nowrap; }
.tl-body { flex: 1; }
.tl-title { font-weight: 600; }
.tl-event { border-left: 3px solid #93c5fd; padding-left: 8px; }
.tl-block { border-left: 3px solid #fbbf24; padding-left: 8px; }
.tl-done .tl-title { text-decoration: line-through; color: var(--muted); }
.tl-past { opacity: .55; }
.badge {
  display: inline-block; font-size: 10px; padding: 1px 7px;
  border-radius: 99px; background: #fef3c7; color: #92400e; margin-left: 6px; vertical-align: 1px;
}

/* task rows */
.task-row { display: flex; align-items: center; gap: 8px; padding: 7px 2px; border-bottom: 1px solid var(--border); }
.task-row:last-child { border-bottom: none; }
.task-overdue { color: var(--red); font-size: 11px; font-weight: 700; }
.check-btn {
  background: none; border: none; font-size: 20px; cursor: pointer;
  padding: 0 4px; line-height: 1; color: var(--primary);
}
.del-btn { background: none; border: none; color: #cbd5e1; font-size: 16px; cursor: pointer; padding: 0 6px; }

/* goals */
.goal-card summary { cursor: pointer; list-style: none; }
.goal-card summary::-webkit-details-marker { display: none; }
.goal-summary { display: flex; flex-direction: column; }
.goal-title { font-weight: 700; font-size: 15px; }
.goal-meta { font-size: 12px; color: var(--amber); }
.goal-done .goal-title { color: var(--muted); }
.goal-why { background: #f8fafc; border-radius: 8px; padding: 8px 10px; font-size: 13px; margin: 10px 0; }
.milestone { margin: 12px 0 4px; padding: 8px 10px; background: #f8fafc; border-radius: 10px; }
.ms-title { font-weight: 600; font-size: 14px; }
.ms-done .ms-title { text-decoration: line-through; color: var(--muted); }
.action-row { display: flex; align-items: center; gap: 4px; padding: 4px 0 4px 14px; font-size: 14px; }
.action-row > span { flex: 1; }
.ac-done > span { text-decoration: line-through; color: var(--muted); }
.inline-form { display: inline; }
.add-action-form { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.goal-form label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.form-row { display: flex; gap: 10px; }
.form-row label { flex: 1; }
.goal-edit { margin-top: 10px; }
.checkbox-label { display: flex !important; align-items: center; gap: 8px; }
.checkbox-label input { width: auto; }
.notice-card { text-align: center; }

/* stats */
.stat-tiles { display: flex; gap: 8px; text-align: center; }
.tile { flex: 1; }
.tile-num { font-size: 22px; font-weight: 800; color: var(--primary); }
.tile-label { font-size: 11px; color: var(--muted); }
.goal-stat-head { display: flex; justify-content: space-between; margin-bottom: 6px; }
.progress-row, .day-row { display: flex; align-items: center; gap: 10px; margin: 6px 0; }
.progress-row .small, .day-row .small { flex: 0 0 auto; }
.day-label { flex: 0 0 64px; font-size: 12px; }
.bar { flex: 1; height: 8px; background: #eef0f6; border-radius: 99px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--primary); border-radius: 99px; }
.bar-green { background: var(--green); }
.bar-red { background: var(--red); }

/* modal */
.overlay {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .5);
  display: flex; align-items: flex-end; justify-content: center; z-index: 50;
}
.modal {
  background: #fff; border-radius: 16px 16px 0 0; width: 100%; max-width: 640px;
  max-height: 85vh; overflow-y: auto; padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
}
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 14px; }
.preview-row { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.preview-row .title { flex: 1; font-size: 14px; }
.preview-row input[type="time"] { border: 1px solid var(--border); border-radius: 8px; padding: 4px; font-family: inherit; }
.unplaced-box { background: #fef2f2; border-radius: 10px; padding: 10px; margin-top: 10px; font-size: 13px; }

.logout-form { text-align: center; margin-top: 24px; }
