/* ===== デザイントークン ===== */
:root {
  color-scheme: light;

  --bg: #f4f3f0;
  --surface: #ffffff;
  --surface-sunken: #faf9f7;
  --text: #23231f;
  --text-soft: #55534d;
  --muted: #8b877f;
  --line: #e6e3dc;
  --line-strong: #d5d1c7;

  --ink: #26251f;          /* 主ボタン */
  --ink-hover: #3a3830;
  --accent: #b4600f;       /* 未完了 */
  --accent-soft: #fdf3e7;
  --success: #2f7a55;      /* 完了 */
  --success-soft: #eef6f1;
  --danger: #b23b3b;
  --danger-soft: #fdefee;

  --ring: rgba(38, 37, 31, .18);
  --shadow-sm: 0 1px 2px rgba(35, 35, 31, .05);
  --shadow-md: 0 1px 2px rgba(35, 35, 31, .05), 0 8px 24px -12px rgba(35, 35, 31, .18);

  --radius: 14px;
  --radius-sm: 9px;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;

    --bg: #17171a;
    --surface: #1f1f23;
    --surface-sunken: #232328;
    --text: #eceae5;
    --text-soft: #c2beb6;
    --muted: #8e8a83;
    --line: #32323a;
    --line-strong: #43434d;

    --ink: #ecead9;
    --ink-hover: #ffffff;
    --accent: #e8a55c;
    --accent-soft: #2e2419;
    --success: #6fc79a;
    --success-soft: #17291f;
    --danger: #e58b8b;
    --danger-soft: #2c1c1c;

    --ring: rgba(236, 234, 229, .22);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-md: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 28px -14px rgba(0, 0, 0, .7);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 40px 20px 80px;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN",
               "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", sans-serif;
  font-size: 15px;
  line-height: 1.65;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

.shell { max-width: 1000px; margin: 0 auto; }

/* ===== ヘッダー ===== */
.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
}
.brand { display: flex; align-items: center; gap: 13px; }
.brand-mark {
  width: 42px;
  height: 42px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: var(--ink);
  color: var(--surface);
  font-size: 19px;
  font-weight: 600;
  letter-spacing: .02em;
  box-shadow: var(--shadow-sm);
}
.page-header h1 {
  margin: 0;
  font-size: 21px;
  font-weight: 650;
  letter-spacing: .01em;
}
.subtitle { margin: 1px 0 0; font-size: 13px; color: var(--muted); }
.header-meta { text-align: right; }
.today {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.storage-mode {
  margin: 2px 0 0;
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
}
.storage-mode:not(:empty)::before {
  content: "";
  display: inline-block;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--line-strong);
  margin-right: 6px;
  vertical-align: middle;
}

/* ===== アイコン ===== */
.icon {
  width: 16px;
  height: 16px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ===== ダッシュボード ===== */
.dashboard {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 22px;
}
.stat {
  position: relative;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px 14px;
  box-shadow: var(--shadow-sm);
}
.stat::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--line-strong);
}
.stat-accent::before { background: var(--accent); }
.stat-done::before { background: var(--success); }
.stat-head {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: .04em;
  color: var(--muted);
}
.stat-value {
  margin: 6px 0 0;
  font-size: 34px;
  font-weight: 640;
  line-height: 1.15;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
  display: flex;
  align-items: baseline;
  gap: 4px;
}
.stat-unit { font-size: 13px; font-weight: 400; color: var(--muted); }
.stat-accent .stat-value { color: var(--accent); }
.stat-done .stat-value { color: var(--success); }

/* ===== カード ===== */
.columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  align-items: start;
}
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 22px 24px;
  box-shadow: var(--shadow-md);
}
.card-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 16px;
  padding-bottom: 13px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
  font-weight: 620;
  letter-spacing: .03em;
}
.card-title .icon { color: var(--muted); }

.list-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 24px 0 11px;
}
.list-head h3 {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .07em;
  color: var(--muted);
}
.count {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-soft);
  background: var(--surface-sunken);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 8px;
  font-variant-numeric: tabular-nums;
}

/* ===== フォーム ===== */
.form { display: flex; flex-direction: column; gap: 9px; }
.form-row { flex-direction: row; }
.form-row input { flex: 1; min-width: 0; }

input, textarea {
  font: inherit;
  width: 100%;
  color: var(--text);
  background: var(--surface-sunken);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
textarea { resize: vertical; min-height: 84px; }
input::placeholder, textarea::placeholder { color: var(--muted); }
input:hover, textarea:hover { border-color: var(--line-strong); }
input:focus, textarea:focus {
  outline: none;
  background: var(--surface);
  border-color: var(--ink);
  box-shadow: 0 0 0 3px var(--ring);
}

/* ===== ボタン ===== */
.btn {
  font: inherit;
  font-size: 14px;
  font-weight: 550;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, color .15s, border-color .15s, transform .06s, box-shadow .15s;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ring); }

.btn-primary {
  background: var(--ink);
  color: var(--surface);
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover { background: var(--ink-hover); }

.btn-small { font-size: 12px; padding: 5px 11px; border-radius: 7px; }

.btn-ghost {
  background: transparent;
  border-color: var(--line-strong);
  color: var(--text-soft);
}
.btn-ghost:hover { border-color: var(--muted); color: var(--text); background: var(--surface-sunken); }

.btn-danger { background: transparent; border-color: var(--line); color: var(--muted); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }

/* ===== 一覧 ===== */
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 9px; }
.item {
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 13px 15px;
  background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
}
.item:hover { border-color: var(--line-strong); box-shadow: var(--shadow-sm); }
.item:hover .item-actions { opacity: 1; }

.item-title { font-weight: 600; line-height: 1.5; word-break: break-word; }
.item-body {
  margin-top: 5px;
  font-size: 14px;
  color: var(--text-soft);
  white-space: pre-wrap;
  word-break: break-word;
}
.item-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 9px;
  font-size: 11.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.item-actions {
  display: flex;
  gap: 7px;
  margin-top: 11px;
  opacity: .55;
  transition: opacity .15s;
}
.item:focus-within .item-actions { opacity: 1; }

.badge {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .03em;
  border-radius: 999px;
  padding: 1px 9px;
  border: 1px solid transparent;
}
.badge-open { color: var(--accent); background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 28%, transparent); }
.badge-done { color: var(--success); background: var(--success-soft); border-color: color-mix(in srgb, var(--success) 28%, transparent); }

.item.done { background: var(--surface-sunken); }
.item.done .item-title { color: var(--muted); text-decoration: line-through; text-decoration-thickness: 1px; }

.empty {
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 20px 14px;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  background: var(--surface-sunken);
}

/* ===== 最新の振り返り（ダッシュボード） ===== */
.latest {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 3px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 15px 18px;
  margin-bottom: 22px;
  box-shadow: var(--shadow-sm);
}
.latest-main { min-width: 0; }
.latest-head {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: .04em;
  color: var(--muted);
}
.latest-week {
  color: var(--text-soft);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.latest-week:not(:empty)::before { content: "／"; color: var(--line-strong); margin-right: 6px; }
.latest-text {
  margin: 6px 0 0;
  font-size: 14px;
  color: var(--text);
  white-space: pre-wrap;
  /* 長い振り返りは2行までにとどめる */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.latest-text.is-empty { color: var(--muted); }
.latest-link {
  flex: none;
  font-size: 12.5px;
  font-weight: 550;
  color: var(--text-soft);
  text-decoration: none;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 5px 13px;
  white-space: nowrap;
  transition: border-color .15s, color .15s, background .15s;
}
.latest-link:hover { color: var(--text); border-color: var(--muted); background: var(--surface-sunken); }

/* ===== 週次の振り返りカード ===== */
.card-wide { grid-column: 1 / -1; }

.field-row { display: flex; align-items: center; gap: 10px; }
.field-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .05em;
  color: var(--muted);
  white-space: nowrap;
}
select {
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--surface-sunken);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px 11px;
  min-width: 240px;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
select:hover { border-color: var(--line-strong); }
select:focus {
  outline: none;
  background: var(--surface);
  border-color: var(--ink);
  box-shadow: 0 0 0 3px var(--ring);
}

.form-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.hint { font-size: 12px; color: var(--muted); }

.badge-week {
  color: var(--text-soft);
  background: var(--surface-sunken);
  border-color: var(--line-strong);
}
.review-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.list-review { margin-top: 0; }
.list-review .item-body { color: var(--text); }

/* ===== エラー ===== */
.error {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--danger-soft);
  border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
  color: var(--danger);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  margin-bottom: 18px;
  font-size: 13.5px;
}
.error[hidden] { display: none; }

/* ===== レスポンシブ ===== */
@media (max-width: 820px) {
  body { padding: 28px 16px 64px; }
  .columns { grid-template-columns: 1fr; }
  .dashboard { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat { padding: 13px 14px 12px; }
  .stat-value { font-size: 27px; }
  .page-header { flex-direction: column; align-items: flex-start; gap: 8px; }
  .header-meta { text-align: left; }
  .latest { flex-direction: column; align-items: stretch; gap: 12px; }
  .latest-link { align-self: flex-start; }
}

@media (max-width: 520px) {
  /* 狭い画面ではダッシュボードを1行1項目のコンパクト表示に */
  .dashboard { grid-template-columns: 1fr; gap: 8px; }
  .stat {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 11px 14px;
  }
  .stat-head { font-size: 13px; }
  .stat-value { margin: 0; font-size: 22px; }
  .card { padding: 18px 16px 20px; }
  .field-row { flex-direction: column; align-items: stretch; gap: 6px; }
  select { min-width: 0; width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
