:root {
  --bg: #f6f6f3;
  --surface: #ffffff;
  --surface-2: #f9f9f7;
  --border: #e7e6e1;
  --text: #1d1d1b;
  --muted: #74736d;
  --faint: #a4a39c;
  --accent: #3d5afe;
  --accent-soft: #eef1ff;
  --warn: #c2410c;
  --warn-soft: #fff1e8;
  --ok: #15803d;
  --ok-soft: #e9f7ee;
  --danger: #dc2626;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 20, 15, .04), 0 4px 16px rgba(20, 20, 15, .04);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141413;
    --surface: #1c1c1a;
    --surface-2: #232321;
    --border: #2f2f2c;
    --text: #ececea;
    --muted: #a09f98;
    --faint: #6e6d67;
    --accent: #8197ff;
    --accent-soft: #23284a;
    --warn: #fb923c;
    --warn-soft: #3a2415;
    --ok: #4ade80;
    --ok-soft: #173322;
    --danger: #f87171;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ---- ヘッダー ---- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 28px; height: 28px;
  border-radius: 8px;
  background: var(--text);
  color: var(--bg);
  display: grid; place-items: center;
  font-weight: 700; font-size: 14px;
}
.brand-name { font-weight: 600; letter-spacing: .01em; }
.today { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }

main { max-width: 1080px; margin: 0 auto; padding: 32px 24px 64px; }

.hero h1 { margin: 0; font-size: 26px; font-weight: 700; letter-spacing: -.01em; }
.hero .sub { margin: 4px 0 24px; color: var(--muted); }

/* ---- ダッシュボード ---- */
.dashboard {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 28px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}
.stat-label { font-size: 13px; color: var(--muted); font-weight: 500; }
.stat-value {
  font-size: 34px;
  font-weight: 700;
  line-height: 1.2;
  margin-top: 6px;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.02em;
}
.stat-accent .stat-value { color: var(--ok); }
.stat-open .stat-value.has-open { color: var(--warn); }
.progress {
  height: 6px;
  margin-top: 12px;
  border-radius: 99px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  width: 0;
  background: var(--ok);
  border-radius: 99px;
  transition: width .4s ease;
}
.stat-note { font-size: 12px; color: var(--muted); margin-top: 6px; }

/* ---- パネル ---- */
.columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  align-items: start;
}
@media (max-width: 800px) {
  .columns { grid-template-columns: 1fr; }
}
@media (max-width: 800px) {
  .dashboard { grid-template-columns: repeat(2, 1fr); }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 0;
}
.panel-head h2 { margin: 0; font-size: 16px; font-weight: 600; }
.count-pill {
  font-size: 12px;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 0 10px;
}

/* ---- 入力欄 ---- */
.composer {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 20px 18px;
  border-bottom: 1px solid var(--border);
}
.composer-inline { flex-direction: row; }
.composer-inline input { flex: 1; }
.composer-actions { display: flex; justify-content: flex-end; }

input[type="text"], textarea {
  font: inherit;
  color: inherit;
  width: 100%;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: none;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
input[type="text"]::placeholder, textarea::placeholder { color: var(--faint); }
input[type="text"]:focus, textarea:focus {
  background: var(--surface);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { resize: vertical; min-height: 76px; }

button {
  font: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}
.btn-primary {
  padding: 9px 18px;
  border-radius: 10px;
  background: var(--text);
  color: var(--bg);
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  transition: transform .1s, opacity .15s;
}
.btn-primary:hover { opacity: .88; }
.btn-primary:active { transform: scale(.97); }
button:focus-visible, input[type="checkbox"]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---- 一覧 ---- */
.list { list-style: none; margin: 0; padding: 6px 0; }
.list li {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
}
.list li:first-child { border-top: none; }
.list:empty { display: none; }

.memo-title { font-weight: 600; }
.memo-body {
  white-space: pre-wrap;
  margin: 4px 0 6px;
  color: var(--muted);
  font-size: 14px;
}
.meta { font-size: 12px; color: var(--faint); font-variant-numeric: tabular-nums; }

/* タスク行 */
.task-row {
  display: flex;
  align-items: center;
  gap: 14px;
  transition: background .15s;
}
.task-row:hover { background: var(--surface-2); }
.task-main { flex: 1; min-width: 0; }
.task-text { word-break: break-word; transition: color .2s; }
.task-text.done { text-decoration: line-through; color: var(--faint); }
.task-meta { display: flex; align-items: center; gap: 8px; margin-top: 2px; }

/* 丸いチェックボックス */
.task-row input[type="checkbox"] {
  appearance: none;
  flex: none;
  width: 22px; height: 22px;
  margin: 0;
  border: 2px solid var(--faint);
  border-radius: 50%;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background .15s, border-color .15s;
}
.task-row input[type="checkbox"]:hover { border-color: var(--ok); }
.task-row input[type="checkbox"]:checked {
  background: var(--ok);
  border-color: var(--ok);
}
.task-row input[type="checkbox"]:checked::after {
  content: "";
  width: 6px; height: 10px;
  border: solid var(--surface);
  border-width: 0 2px 2px 0;
  transform: translateY(-1px) rotate(45deg);
}

.badge {
  font-size: 11px;
  font-weight: 600;
  padding: 1px 8px;
  border-radius: 99px;
}
.badge.open { background: var(--warn-soft); color: var(--warn); }
.badge.done { background: var(--ok-soft); color: var(--ok); }

.btn-delete {
  flex: none;
  width: 32px; height: 32px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: var(--faint);
  opacity: 0;
  transition: opacity .15s, background .15s, color .15s;
}
.task-row:hover .btn-delete, .btn-delete:focus-visible { opacity: 1; }
.btn-delete:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
@media (hover: none) { .btn-delete { opacity: 1; } }

/* ---- 最新の振り返り（ダッシュボード） ---- */
.latest-review {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 20px;
  margin: -12px 0 28px;
}
.latest-review-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.latest-review-week { font-size: 13px; font-weight: 600; }
.latest-review-text {
  margin: 6px 0 0;
  white-space: pre-wrap;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.latest-review-text.placeholder { color: var(--faint); }
.link {
  margin-left: auto;
  font-size: 13px;
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}
.link:hover { text-decoration: underline; }

/* ---- 週次の振り返り ---- */
.review-panel { margin-top: 20px; scroll-margin-top: 70px; }
.review-grid { display: grid; grid-template-columns: 3fr 2fr; }
@media (max-width: 800px) { .review-grid { grid-template-columns: 1fr; } }
.review-editor { border-bottom: none; border-right: 1px solid var(--border); }
@media (max-width: 800px) {
  .review-editor { border-right: none; border-bottom: 1px solid var(--border); }
}
.review-editor .composer-actions { align-items: center; gap: 8px; }
.review-editor .composer-actions .meta { margin-right: auto; }

.week-nav { display: flex; align-items: center; gap: 6px; }
.week-label { flex: 1; text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; }
.week-tag {
  font-size: 11px;
  font-weight: 600;
  margin-left: 6px;
  padding: 1px 8px;
  border-radius: 99px;
  background: var(--accent-soft);
  color: var(--accent);
}
.week-tag:empty { display: none; }
.btn-icon {
  width: 32px; height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 18px;
  line-height: 1;
  color: var(--muted);
}
.btn-icon:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.btn-icon:disabled { opacity: .35; cursor: default; }
.btn-ghost {
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 13px;
  color: var(--muted);
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.danger-text:hover { color: var(--danger); }

.week-stats { display: flex; gap: 8px; flex-wrap: wrap; }
.week-stat {
  font-size: 12px;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 2px 10px;
}
.week-stat b { color: var(--text); font-variant-numeric: tabular-nums; }

.review-history { padding: 14px 0 6px; min-width: 0; }
.review-history h3 { margin: 0 20px 4px; font-size: 13px; color: var(--muted); font-weight: 600; }
.review-list { max-height: 340px; overflow-y: auto; }
.review-list li { cursor: pointer; transition: background .15s; }
.review-list li:hover { background: var(--surface-2); }
.review-list li.selected { background: var(--accent-soft); }
.review-item-week { font-size: 13px; font-weight: 600; }
.review-item-text {
  font-size: 14px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.empty {
  margin: 0;
  padding: 28px 20px 32px;
  text-align: center;
  color: var(--faint);
  font-size: 14px;
}
