/* ===== デザイントークン ===== */
:root {
  --bg: #f5f6f8;
  --bg-grad: radial-gradient(1200px 600px at 50% -280px, #e9edf7 0%, transparent 70%);
  --surface: #ffffff;
  --surface-soft: #fafbfc;
  --text: #16202e;
  --text-soft: #48566a;
  --muted: #8894a5;
  --line: #e6e9ef;
  --line-soft: #eef0f4;
  --line-hover: #d5dae3;
  --brand: #3d5afe;
  --brand-soft: rgba(61, 90, 254, .10);
  --accent: #e2732c;
  --accent-soft: rgba(226, 115, 44, .12);
  --done: #12926a;
  --done-soft: rgba(18, 146, 106, .12);
  --danger: #d3453f;
  --danger-soft: rgba(211, 69, 63, .10);
  --shadow-sm: 0 1px 2px rgba(16, 26, 44, .04), 0 1px 3px rgba(16, 26, 44, .04);
  --shadow-md: 0 2px 4px rgba(16, 26, 44, .04), 0 8px 24px rgba(16, 26, 44, .06);
  --radius: 14px;
  --radius-sm: 10px;
  --ease: cubic-bezier(.32, .72, .28, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1218;
    --bg-grad: radial-gradient(1200px 600px at 50% -280px, #1a2230 0%, transparent 70%);
    --surface: #161c25;
    --surface-soft: #1b222c;
    --text: #e8edf4;
    --text-soft: #b3becd;
    --muted: #7d8899;
    --line: #262e3a;
    --line-soft: #212934;
    --line-hover: #3a4553;
    --brand: #7c8dff;
    --brand-soft: rgba(124, 141, 255, .16);
    --accent: #f0954f;
    --accent-soft: rgba(240, 149, 79, .16);
    --done: #35c295;
    --done-soft: rgba(53, 194, 149, .16);
    --danger: #f0736d;
    --danger-soft: rgba(240, 115, 109, .14);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-md: 0 2px 4px rgba(0, 0, 0, .25), 0 10px 28px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  font-family: "Hiragino Sans", "Yu Gothic UI", "Noto Sans JP", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.7;
  color: var(--text);
  background: var(--bg);
  background-image: var(--bg-grad);
  background-repeat: no-repeat;
  -webkit-font-smoothing: antialiased;
}

.shell {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 20px 64px;
}

/* ===== ヘッダー ===== */
.site-header { padding: 44px 0 26px; }

.brand { display: flex; align-items: center; gap: 13px; }

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: none;
  border-radius: 12px;
  color: #fff;
  background: linear-gradient(145deg, var(--brand), #6f4dff);
  box-shadow: 0 4px 12px rgba(61, 90, 254, .25);
}
.brand-mark svg { width: 22px; height: 22px; }

.site-header h1 {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: .01em;
}
.tagline {
  margin: 1px 0 0;
  font-size: .84rem;
  color: var(--muted);
}

/* ===== ダッシュボード ===== */
.dashboard {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 22px;
}

.stat {
  position: relative;
  overflow: hidden;
  padding: 15px 16px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.stat::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--brand);
  opacity: .55;
}
.stat.is-accent::before { background: var(--accent); opacity: 1; }

.stat-label {
  display: block;
  font-size: .74rem;
  font-weight: 600;
  letter-spacing: .08em;
  color: var(--muted);
}
.stat-value {
  display: flex;
  align-items: baseline;
  gap: 3px;
  margin-top: 2px;
  font-size: 1.95rem;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
}
.stat-unit { font-size: .78rem; font-weight: 600; color: var(--muted); }
.stat.is-accent .stat-value { color: var(--accent); }

/* ダッシュボード内：最新の振り返り */
.latest {
  position: relative;
  overflow: hidden;
  margin-bottom: 22px;
  padding: 15px 18px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.latest::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--done);
}
.latest-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}
.latest-label {
  font-size: .74rem;
  font-weight: 600;
  letter-spacing: .08em;
  color: var(--muted);
}
.latest-week {
  font-size: .84rem;
  font-weight: 700;
  color: var(--done);
  font-variant-numeric: tabular-nums;
}
.latest-comment {
  margin: 4px 0 0;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
  font-size: .95rem;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
}
.latest-comment.is-empty { color: var(--muted); font-size: .88rem; }
.latest-meta {
  margin: 7px 0 0;
  font-size: .76rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ===== カード ===== */
.card {
  margin-bottom: 18px;
  padding: 20px 22px 22px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
}

.card-head {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 16px;
}
.card-head h2 {
  margin: 0;
  font-size: 1.02rem;
  font-weight: 700;
  letter-spacing: .01em;
}
.card-icon {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  flex: none;
  border-radius: 9px;
  color: var(--brand);
  background: var(--brand-soft);
}
.card-icon svg { width: 17px; height: 17px; }

.count-chip {
  margin-left: auto;
  min-width: 26px;
  padding: 1px 9px;
  text-align: center;
  font-size: .76rem;
  font-weight: 600;
  color: var(--text-soft);
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}

/* ===== フォーム ===== */
.form {
  display: flex;
  flex-direction: column;
  gap: 9px;
  margin-bottom: 16px;
}
.form-inline { flex-direction: row; }
.form-inline input { flex: 1; }
.form-actions { display: flex; align-items: center; gap: 12px; justify-content: flex-end; }

.field-label {
  font-size: .78rem;
  font-weight: 600;
  letter-spacing: .04em;
  color: var(--muted);
}
.hint { margin-right: auto; font-size: .78rem; color: var(--accent); }

input[type="text"], textarea, select {
  width: 100%;
  padding: 10px 13px;
  font: inherit;
  line-height: 1.6;
  color: inherit;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  resize: vertical;
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease), background-color .15s var(--ease);
}
input[type="text"]::placeholder, textarea::placeholder { color: var(--muted); }
input[type="text"]:hover, textarea:hover, select:hover { border-color: var(--line-hover); }
input[type="text"]:focus, textarea:focus, select:focus {
  outline: none;
  background: var(--surface);
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}

select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 36px;
  cursor: pointer;
  color-scheme: light dark;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238894a5' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9.5 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 15px;
}

.btn {
  padding: 9px 18px;
  font: inherit;
  font-size: .9rem;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
  transition: background-color .15s var(--ease), transform .1s var(--ease), box-shadow .15s var(--ease);
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

.btn-primary {
  color: #fff;
  background: var(--brand);
  box-shadow: 0 1px 2px rgba(16, 26, 44, .12);
}
.btn-primary:hover { background: color-mix(in srgb, var(--brand) 88%, #000); }

/* ===== 一覧 ===== */
.list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.list:empty { display: none; }

.item {
  position: relative;
  padding: 13px 15px;
  background: var(--surface-soft);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  transition: border-color .15s var(--ease), background-color .15s var(--ease);
}
.item:hover { border-color: var(--line); }

.item-head {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.item-title {
  flex: 1;
  font-weight: 600;
  letter-spacing: .01em;
  word-break: break-word;
}
.item-body {
  margin: 5px 0 0;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-soft);
  font-size: .92rem;
}
.item-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 9px;
  font-size: .76rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* タスク */
.task-main { flex: 1; min-width: 0; }
.task.done { background: var(--surface); }
.task.done .item-title { color: var(--muted); text-decoration: line-through; text-decoration-thickness: 1px; }

.task-check {
  appearance: none;
  -webkit-appearance: none;
  flex: none;
  width: 19px;
  height: 19px;
  margin: 3px 0 0;
  border: 1.5px solid var(--line-hover);
  border-radius: 6px;
  background: var(--surface);
  cursor: pointer;
  transition: background-color .15s var(--ease), border-color .15s var(--ease);
}
.task-check:hover { border-color: var(--done); }
.task-check:checked {
  background: var(--done);
  border-color: var(--done);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m5 12.5 4.5 4.5L19 7'/%3E%3C/svg%3E");
  background-size: 13px;
  background-position: center;
  background-repeat: no-repeat;
}
.task-check:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

.badge {
  display: inline-block;
  padding: 1px 9px;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .02em;
  color: var(--accent);
  background: var(--accent-soft);
}
.badge.done { color: var(--done); background: var(--done-soft); }
.badge.week { color: var(--text-soft); background: var(--brand-soft); }

/* 削除ボタン（普段は控えめ、ホバーで出す） */
.btn-icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  opacity: .45;
  transition: opacity .15s var(--ease), color .15s var(--ease), background-color .15s var(--ease);
}
.btn-icon svg { width: 15px; height: 15px; }
.item:hover .btn-icon { opacity: 1; }
.btn-icon:hover { color: var(--danger); background: var(--danger-soft); }
.btn-icon:focus-visible { opacity: 1; outline: 2px solid var(--brand); outline-offset: 1px; }

/* ===== 補助テキスト ===== */
.empty {
  margin: 2px 0 0;
  padding: 14px 0;
  text-align: center;
  font-size: .86rem;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: var(--radius-sm);
}
.error {
  margin: -6px 0 12px;
  padding: 8px 12px;
  font-size: .84rem;
  color: var(--danger);
  background: var(--danger-soft);
  border-radius: var(--radius-sm);
}

.site-footer {
  margin-top: 26px;
  text-align: center;
  font-size: .78rem;
  color: var(--muted);
}
.site-footer code {
  padding: 1px 6px;
  font-size: .95em;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
}

/* ===== スマホ ===== */
@media (max-width: 620px) {
  .shell { padding: 0 14px 44px; }
  .site-header { padding: 30px 0 20px; }
  .dashboard { grid-template-columns: 1fr; gap: 9px; }
  .stat { display: flex; align-items: center; justify-content: space-between; padding: 12px 15px; }
  .stat-value { font-size: 1.5rem; }
  .card { padding: 18px 16px 20px; }
  /* ヒントとボタンを横に詰め込まず、縦に積む */
  .form-actions { flex-direction: column; align-items: stretch; gap: 8px; }
  .hint { margin-right: 0; }
  .latest-comment { -webkit-line-clamp: 4; }
}

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