/* ===========================================================================
   デザイントークン
   =========================================================================== */

:root {
  /* 背景は少し温かみのある生成り。上部にバイオレットとピンクのもやを重ねる */
  --bg: #f7f5f2;
  --bg-tint: rgba(124, 92, 255, 0.11);
  --bg-tint-2: rgba(255, 105, 170, 0.09);
  --surface: #ffffff;
  --surface-sunken: #f7f5fa;

  --text: #1a1726;
  --text-soft: #4b4761;
  --muted: #7c7791;
  --faint: #aaa5bb;

  --border: #eae6f0;
  --border-soft: #f2eff7;

  /* 差し色はバイオレット。--accent-2 と組み合わせてグラデーションにする */
  --accent: #6c4cf1;
  --accent-hover: #5a39e3;
  /* グラデーションの上に白文字を置くので、ピンクは読める濃さまで落とす */
  --accent-2: #d92a78;
  --accent-soft: #f1ecff;
  --accent-line: #ddd3ff;
  --gradient: linear-gradient(135deg, var(--accent), var(--accent-2));

  --danger: #e5395f;
  --danger-soft: #fef0f3;
  --danger-line: #fbd2dc;

  --done: #00a37a;
  --done-soft: #e7faf3;
  --done-line: #b5ebd7;

  --warn: #b4690e;
  --warn-soft: #fdf4e5;
  --warn-line: #f6ddb6;

  --radius-lg: 20px;
  --radius: 14px;
  --radius-sm: 10px;

  /* 影はグレーではなく、差し色をうっすら混ぜた紫寄りにする */
  --shadow-sm: 0 1px 2px rgba(38, 24, 74, 0.05);
  --shadow: 0 1px 2px rgba(38, 24, 74, 0.05), 0 8px 20px -10px rgba(76, 45, 160, 0.22);
  --shadow-lift: 0 2px 6px rgba(38, 24, 74, 0.07), 0 18px 40px -16px rgba(76, 45, 160, 0.34);

  --ring: 0 0 0 3px rgba(108, 76, 241, 0.18);
}

@media (prefers-color-scheme: dark) {
  :root {
    /* 暗い側も真っ黒ではなく、紫を含んだ黒にして差し色となじませる */
    --bg: #0d0b14;
    --bg-tint: rgba(124, 92, 255, 0.24);
    --bg-tint-2: rgba(255, 93, 158, 0.14);
    --surface: #17131f;
    --surface-sunken: #120f1a;

    --text: #f2eefb;
    --text-soft: #cbc4de;
    --muted: #948da9;
    --faint: #6f6885;

    --border: #292339;
    --border-soft: #211c2f;

    --accent: #9d86ff;
    --accent-hover: #b4a3ff;
    --accent-2: #ff7cb4;
    --accent-soft: #1e1833;
    --accent-line: #372c5c;

    --danger: #ff7a92;
    --danger-soft: #2a161f;
    --danger-line: #4c2734;

    --done: #4fd8a4;
    --done-soft: #10261f;
    --done-line: #234a3a;

    --warn: #f0bd72;
    --warn-soft: #2a2010;
    --warn-line: #4a3a1e;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.45);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.45), 0 8px 20px -10px rgba(0, 0, 0, 0.75);
    --shadow-lift: 0 2px 6px rgba(0, 0, 0, 0.5), 0 18px 38px -14px rgba(0, 0, 0, 0.85);

    --ring: 0 0 0 3px rgba(157, 134, 255, 0.26);
  }
}

/* ===========================================================================
   ベース
   =========================================================================== */

* { box-sizing: border-box; }

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

body {
  margin: 0;
  padding: 0 20px 64px;
  min-height: 100vh;
  /* 2色のもやを左右にずらして重ね、単色より奥行きのある背景にする */
  background:
    radial-gradient(820px 420px at 8% -14%, var(--bg-tint), transparent 58%),
    radial-gradient(700px 380px at 92% -8%, var(--bg-tint-2), transparent 56%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic ProN",
    "Yu Gothic UI", Meiryo, system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

main {
  max-width: 1040px;
  margin: 0 auto;
  padding-top: 40px;
}

svg {
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ===========================================================================
   ダッシュボード
   =========================================================================== */

.dashboard {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 26px;
}

.stat {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 18px 20px 16px;
  display: grid;
  grid-template-columns: 34px 1fr;
  grid-template-rows: auto auto;
  column-gap: 12px;
  align-items: center;
  transition: box-shadow 0.2s ease, transform 0.2s ease;
}

.stat:hover {
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}

.stat-icon {
  grid-row: 1 / span 2;
  width: 34px;
  height: 34px;
  padding: 7px;
  border-radius: 10px;
  background: var(--surface-sunken);
  border: 1px solid var(--border-soft);
  color: var(--muted);
}

.stat-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.stat-value {
  font-size: 32px;
  font-weight: 650;
  line-height: 1.1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.stat-accent {
  background: linear-gradient(180deg, var(--accent-soft), var(--surface) 78%);
  border-color: var(--accent-line);
}

.stat-accent .stat-icon {
  background: var(--surface);
  border-color: var(--accent-line);
  color: var(--accent);
}

/* 数字だけグラデーションで塗る */
.stat-accent .stat-value {
  color: var(--accent);
  background: var(--gradient);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* 期限切れのタスクがあるときの「未完了タスク」。青ではなく赤で出す */
.stat-danger {
  background: linear-gradient(180deg, var(--danger-soft), var(--surface) 78%);
  border-color: var(--danger-line);
}

.stat-danger .stat-icon {
  background: var(--surface);
  border-color: var(--danger-line);
  color: var(--danger);
}

/* こちらは赤の単色にしたいので、上のグラデーション塗りを打ち消す */
.stat-danger .stat-value {
  color: var(--danger);
  background: none;
  -webkit-text-fill-color: currentColor;
}

/* ===========================================================================
   入力ウィンドウを開くボタン
   =========================================================================== */

.toolbar {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.toolbar-hint {
  font-size: 12.5px;
  color: var(--muted);
}

/* ===========================================================================
   パネル
   =========================================================================== */

/* ウィンドウの中で、メモとタスクのどちらを入力するか選ぶタブ */
.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 18px;
  padding: 5px;
  background: var(--surface-sunken);
  border: 1px solid var(--border-soft);
  border-radius: 14px;
}

.tabs[hidden] { display: none; }

.tab {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 14px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  font: inherit;
  font-size: 14.5px;
  font-weight: 650;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease,
    box-shadow 0.15s ease;
}

.tab:hover { background: var(--surface); color: var(--text-soft); }

.tab:focus-visible { outline: none; box-shadow: var(--ring); }

.tab[aria-selected="true"] {
  background: var(--accent-soft);
  border-color: var(--accent-line);
  color: var(--accent);
}

.tab-icon {
  width: 17px;
  height: 17px;
  flex-shrink: 0;
}

.columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  align-items: start;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 22px 24px 26px;
}

.panel-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 14px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--border-soft);
}

.panel-icon {
  width: 28px;
  height: 28px;
  padding: 5px;
  border-radius: 9px;
  background: var(--gradient);
  color: #fff;
  flex-shrink: 0;
}

.panel h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 650;
  letter-spacing: 0.01em;
}

/* ===========================================================================
   入力ウィンドウ（ポップアップ）
   =========================================================================== */

.modal {
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lift);
  overflow: hidden;
}

.modal::backdrop {
  background: rgba(26, 18, 48, 0.42);
  backdrop-filter: blur(3px);
}

/* 確認ウィンドウは中身が少ないので、幅を狭くする */
.modal-narrow { width: min(400px, calc(100vw - 32px)); }

.confirm-text {
  margin: 0 0 4px;
  font-size: 14px;
  line-height: 1.7;
  word-break: break-word;
}

@media (prefers-color-scheme: dark) {
  .modal::backdrop { background: rgba(6, 3, 14, 0.66); }
}

.modal[open] { animation: modal-in 0.18s ease both; }

@keyframes modal-in {
  from { opacity: 0; transform: translateY(-6px) scale(0.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border-soft);
}

.modal-title {
  margin: 0;
  font-size: 16px;
  font-weight: 650;
}

.modal-close {
  margin-left: auto;
  width: 30px;
  height: 30px;
  padding: 6px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.modal-close:hover { background: var(--surface-sunken); color: var(--text); }
.modal-close:focus-visible { outline: none; box-shadow: var(--ring); }

.modal-body {
  padding: 18px 20px 20px;
  max-height: calc(100vh - 140px);
  overflow-y: auto;
}

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 6px;
  padding-top: 16px;
  border-top: 1px solid var(--border-soft);
}

.modal-foot .btn-primary { align-self: auto; }

/* ===========================================================================
   入力フォーム
   =========================================================================== */

.form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.form[hidden] { display: none; }

/* 期限の日付と時を1行に並べる */
.form-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.form-row:empty { display: none; }

/* 期限の入力方法を選ぶ（入力しない／日付のみ／日付と時） */
.due-modes {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}

.due-label {
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-right: 2px;
}

/* 見た目はラベル側で作るが、キーボードと読み上げからは触れるようにしておく */
.mode input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.mode span {
  display: inline-block;
  padding: 4px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface-sunken);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease,
    box-shadow 0.15s ease;
}

.mode span:hover { background: var(--surface); color: var(--text-soft); }

.mode input:checked + span {
  background: var(--accent-soft);
  border-color: var(--accent-line);
  color: var(--accent);
}

.mode input:focus-visible + span { box-shadow: var(--ring); }

.input-due {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  background-color: var(--surface-sunken);
  color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

.input-due[hidden] { display: none; }

.input-due:hover { background-color: var(--surface); }

.input-due:focus {
  outline: none;
  background-color: var(--surface);
  border-color: var(--accent);
  box-shadow: var(--ring);
}

.input-hour {
  padding-right: 34px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%237c7791' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M6 9l6 6 6-6'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 15px;
  appearance: none;
  cursor: pointer;
}

input[type="text"], textarea {
  width: 100%;
  padding: 10px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 14.5px;
  background: var(--surface-sunken);
  color: var(--text);
  resize: vertical;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

input[type="text"]::placeholder, textarea::placeholder { color: var(--faint); }

input[type="text"]:hover, textarea:hover { border-color: var(--border); background: var(--surface); }

input[type="text"]:focus, textarea:focus {
  outline: none;
  background: var(--surface);
  border-color: var(--accent);
  box-shadow: var(--ring);
}

/* ===========================================================================
   ボタン
   =========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 15px;
  background: var(--surface);
  color: var(--text-soft);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease,
    box-shadow 0.15s ease, transform 0.1s ease;
}

/* display を指定しているので、hidden 属性を効かせるために打ち消しておく */
.btn[hidden] { display: none; }

.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn:active { transform: translateY(1px); }

.btn-icon {
  width: 15px;
  height: 15px;
  stroke-width: 2.2;
  flex-shrink: 0;
}

.btn-primary {
  background: var(--gradient);
  border-color: transparent;
  color: #fff;
  align-self: flex-start;
  box-shadow: 0 1px 2px rgba(38, 24, 74, 0.12), 0 6px 16px -6px rgba(108, 76, 241, 0.55);
}

/* グラデーションのままなので、色を差し替えず明るさで反応させる */
.btn-primary:hover {
  filter: brightness(1.07) saturate(1.05);
  box-shadow: 0 1px 2px rgba(38, 24, 74, 0.12), 0 8px 20px -6px rgba(108, 76, 241, 0.6);
}

@media (prefers-color-scheme: dark) {
  .btn-primary { color: #180f26; box-shadow: var(--shadow-sm); }
  /* 日付ピッカーのカレンダーアイコンを暗い背景に合わせる */
  .input-date { color-scheme: dark; }
  /* 「時」の下向き矢印も暗い背景用の色に差し替える */
  .input-hour {
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23948da9' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M6 9l6 6 6-6'/></svg>");
  }
}

/* 1行に並べたときは、期限の入力欄と下端をそろえる */
/* 入力ウィンドウを開く、少し大きめのボタン */
.btn-lg {
  padding: 12px 22px;
  font-size: 15px;
  border-radius: 11px;
}

.btn-small {
  padding: 4px 11px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  background: transparent;
  border-color: transparent;
}

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

/* 削除の確認ウィンドウで押す、赤いボタン */
.btn-delete {
  color: #fff;
  background: var(--danger);
  border-color: transparent;
  box-shadow: var(--shadow-sm);
}

.btn-delete:hover { filter: brightness(1.08); }

/* ===========================================================================
   一覧
   =========================================================================== */


.list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.item {
  position: relative;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 13px 15px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.18s ease, border-color 0.18s ease, transform 0.18s ease;
  animation: item-in 0.22s ease both;
}

.item:hover {
  box-shadow: var(--shadow);
  border-color: var(--border);
  transform: translateY(-1px);
}

@keyframes item-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.item-head {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.item-title {
  flex: 1;
  min-width: 0;
  font-weight: 620;
  font-size: 15px;
  letter-spacing: 0.005em;
  word-break: break-word;
}

.item-body {
  margin: 7px 0 0;
  font-size: 14px;
  color: var(--text-soft);
  white-space: pre-wrap;
  word-break: break-word;
}

.item-meta {
  margin-top: 10px;
  padding-top: 9px;
  border-top: 1px dashed var(--border-soft);
  font-size: 11.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px 12px;
}

/* 削除ボタンは控えめに置き、カードに触れたときにはっきりさせる */
.item-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
  opacity: 0.5;
  transition: opacity 0.18s ease;
}

.item:hover .item-actions,
.item:focus-within .item-actions { opacity: 1; }

/* バッジ */
.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 1px 9px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.05em;
  border: 1px solid;
}

.badge-active {
  color: var(--warn);
  border-color: var(--warn-line);
  background: var(--warn-soft);
}

.badge-done {
  color: var(--done);
  border-color: var(--done-line);
  background: var(--done-soft);
}

/* 期限切れの未完了タスクは、カード全体を赤くして目立たせる */
.task-over {
  background: linear-gradient(90deg, var(--danger-soft), var(--surface) 60%);
  border-color: var(--danger-line);
}

.task-over .item-title,
.task-over .item-meta { color: var(--danger); }

.task-over .item-meta { border-top-color: var(--danger-line); }

.task-over .badge-active {
  color: var(--danger);
  border-color: var(--danger-line);
  background: var(--danger-soft);
}

.task-over .item-check { accent-color: var(--danger); }

/* 完了タスク */
.task-done {
  background: linear-gradient(90deg, var(--done-soft), var(--surface) 30%);
  border-color: var(--done-line);
}

.task-done .item-title {
  text-decoration: line-through;
  text-decoration-color: var(--faint);
  text-decoration-thickness: 1.5px;
  color: var(--muted);
  font-weight: 550;
}

.item-check {
  width: 17px;
  height: 17px;
  margin: 3px 0 0;
  cursor: pointer;
  accent-color: var(--done);
  flex-shrink: 0;
}

.item-check:focus-visible { outline: none; box-shadow: var(--ring); border-radius: 4px; }

/* 空のとき */
.empty {
  margin: 0;
  padding: 22px 14px;
  text-align: center;
  color: var(--faint);
  font-size: 13px;
  background: var(--surface-sunken);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.empty[hidden] { display: none; }

/* ===========================================================================
   トースト
   =========================================================================== */

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(14px) scale(0.97);
  background: #1d1730;
  color: #f6f2ff;
  padding: 11px 20px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: var(--shadow-lift);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s cubic-bezier(0.2, 0.9, 0.3, 1.2);
  z-index: 50;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0) scale(1);
}

.toast.error {
  background: var(--danger);
  color: #fff;
  border-color: transparent;
}

@media (prefers-color-scheme: dark) {
  .toast { background: #2a2340; }
  .toast.error { color: #24101a; }
}

/* ===========================================================================
   レスポンシブ
   =========================================================================== */

@media (max-width: 860px) {
  .columns { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
  body { padding: 0 14px 56px; }
  main { padding-top: 24px; }

  .dashboard { grid-template-columns: 1fr; gap: 10px; }

  .stat {
    grid-template-columns: 34px 1fr auto;
    grid-template-rows: auto;
    padding: 14px 16px;
  }

  .stat-icon { grid-row: 1; }
  .stat-value { font-size: 24px; }

  .panel { padding: 18px 16px 22px; }
  .input-date { flex: 1; min-width: 0; }
}

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