/* ===== デイリーミッション スタイル ===== */

:root {
  --bg: #1b1e2e;
  --bg-card: #262b40;
  --bg-input: #1f2336;
  --text: #eef0f8;
  --text-dim: #9aa0b8;
  --accent: #7c8cff;
  --accent-strong: #5a6cf0;
  --pink: #ff8fb8;
  --gold: #ffd166;
  --green: #6fe3a5;
  --red: #ff7b7b;
  --border: #363c58;
  --radius: 14px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.hidden { display: none !important; }

.view { min-height: 100vh; }

/* ===== カード共通 ===== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

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

/* ===== 2カラムレイアウト（左：ミッション／右：メモ） ===== */
/* ログイン後の container だけ2カラム化。左カラムは従来の640px幅を維持する */
#app-view .container {
  max-width: 952px; /* 640(左) + 16(gap) + 280(右) + 16(padding両側は含まず調整) */
  display: grid;
  grid-template-columns: minmax(0, 640px) 280px;
  gap: 16px;
  align-items: start;
  justify-content: center;
}
.layout-main { min-width: 0; }
.layout-side {
  /* スクロールしてもメモが見えるように追従。伸びすぎたらメモ側だけスクロール */
  position: sticky;
  top: 16px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
}

/* 狭い画面では1カラムに戻し、メモをミッション一覧の下に回り込ませる */
@media (max-width: 900px) {
  #app-view .container {
    display: block;
    max-width: 640px;
  }
  .layout-side {
    position: static;
    max-height: none;
    overflow-y: visible;
  }
}

/* ===== ボタン ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
  background: var(--bg-input);
  transition: transform 0.08s ease, filter 0.15s ease;
}
.btn:hover { filter: brightness(1.15); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--accent-strong); }
.btn-google { background: #fff; color: #333; width: 100%; }
.btn-ghost { background: transparent; border: 1px solid var(--border); color: var(--text-dim); }
.btn-small { padding: 6px 10px; font-size: 13px; }

.g-icon {
  font-weight: 800;
  background: linear-gradient(135deg, #4285f4, #ea4335, #fbbc05, #34a853);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* ===== Dailyn ロゴ ===== */
.dailyn-logo {
  font-family: 'Nunito', sans-serif;
  font-weight: 800;
  letter-spacing: -0.5px;
  display: inline-flex;
  align-items: baseline;
  line-height: 1;
  color: #ffffff; /* 暗い背景前提。明るい背景に置くならベース文字は #1a1a2e などに */
}

/* "n" 部分（ピンク＆バッジの基準位置） */
.dailyn-logo__n {
  position: relative;
  color: #D4537E;
}

/* n の右上のカウンター風バッジ（×10 は装飾の固定表示）
   n に重ねず、右上に離して浮かせる配置 */
.dailyn-logo__badge {
  position: absolute;
  top: -1.0em;
  right: -2.0em;
  font-family: 'Nunito', sans-serif;
  font-weight: 800;
  color: #ffffff;
  background: #D4537E;
  border-radius: 8px;
  padding: 1px 6px;
  line-height: 1.2;
  white-space: nowrap;
}

/* サイズ違い：ヘッダー用（小さめ）
   padding はバッジのはみ出しぶんの余白（上と右） */
.dailyn-logo--sm { font-size: 24px; padding: 8px 24px 0 0; }
.dailyn-logo--sm .dailyn-logo__badge { font-size: 10px; }

/* サイズ違い：ログイン用（大きめ） */
.dailyn-logo--lg { font-size: 48px; padding: 12px 36px 0 0; }
.dailyn-logo--lg .dailyn-logo__badge { font-size: 15px; }

/* タグライン */
.dailyn-tagline {
  font-family: 'Nunito', sans-serif;
  font-weight: 600;
  color: rgba(255,255,255,0.7);
  font-size: 14px;
  margin-top: 12px;
  text-align: center;
}

/* ログイン画面でロゴを中央寄せ（バッジぶん少し左右に余白を取る） */
.logo-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 24px;
  padding-right: 12px;
}

/* ===== ログイン画面 ===== */
#auth-view, #setup-notice {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
#auth-view.hidden, #setup-notice.hidden { display: none !important; }

.auth-card { width: 100%; max-width: 400px; }

.app-title { font-size: 24px; text-align: center; margin-bottom: 4px; }
.app-subtitle { text-align: center; color: var(--text-dim); font-size: 13px; margin-bottom: 20px; }

.divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-dim);
  font-size: 12px;
  margin: 16px 0;
}
.divider::before, .divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

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

input, select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  padding: 10px 12px;
  font-size: 15px;
  outline: none;
}
input:focus, select:focus { border-color: var(--accent); }

.auth-switch { text-align: center; font-size: 13px; color: var(--text-dim); margin-top: 12px; }
.auth-switch a { color: var(--accent); text-decoration: none; }

.auth-error { color: var(--red); font-size: 13px; margin-top: 12px; text-align: center; }
.auth-info { color: var(--green); font-size: 13px; margin-top: 12px; text-align: center; }

/* ===== ヘッダー ===== */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 16px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.header-title { font-weight: 700; }
.header-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.user-label { font-size: 12px; color: var(--text-dim); max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sync-status {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-dim);
}
.sync-status.saved { color: var(--green); border-color: var(--green); }
.sync-status.syncing { color: var(--gold); border-color: var(--gold); }
.sync-status.offline { color: var(--red); border-color: var(--red); }

/* ===== ステータスエリア ===== */
.level-row { display: flex; align-items: center; gap: 16px; margin-bottom: 18px; }

.level-badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 72px;
  height: 72px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 25%, #8a97ff, var(--accent-strong));
  box-shadow: 0 0 18px rgba(124, 140, 255, 0.45);
}
.level-label { font-size: 11px; opacity: 0.85; }
.level-value { font-size: 26px; font-weight: 800; line-height: 1; }

.exp-block, .pt-block { flex: 1; }

.bar-header {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.bar {
  position: relative;
  height: 14px;
  background: var(--bg-input);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.bar-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  transition: width 0.5s ease;
}
.exp-fill { background: linear-gradient(90deg, #7c8cff, #b48cff); }
.pt-fill { background: linear-gradient(90deg, #ffb35c, var(--gold)); }

.pt-ticks .tick {
  position: absolute;
  top: 0;
  width: 1px;
  height: 100%;
  background: rgba(255, 255, 255, 0.25);
}

.daily-bonus-msg { margin-top: 8px; font-size: 13px; color: var(--gold); }

/* ===== タブ切り替え ===== */
.tab-bar {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 5px;
}
.tab-btn {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 700;
  padding: 9px 4px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active {
  background: var(--accent-strong);
  color: #fff;
}

/* 進捗（0/2）と期限バッジを横並びにする行 */
.task-meta-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* ===== 期限バッジ ===== */
.due-badge {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 8px;
  white-space: nowrap;
}
.due-badge.soon { color: var(--gold); border-color: var(--gold); }
.due-badge.overdue { color: var(--red); border-color: var(--red); }

/* 期限フォーム */
.due-editor { margin-top: 12px; }
.due-editor .type-toggle { margin-bottom: 8px; }
/* 期限日（日数）と時刻を横並びにする行。狭い画面では折り返す */
.due-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

/* プリセットの「メインへ」ボタン */
.btn-main-add {
  background: transparent;
  border: 1px solid var(--accent);
  color: var(--accent);
}

/* セクション見出し＋右側のアクションボタン */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}
.section-header .section-title { margin-bottom: 0; }

/* ===== タスク一覧 ===== */
.section-title { font-size: 16px; margin-bottom: 12px; }
.section-note { font-size: 12px; color: var(--text-dim); margin: -6px 0 12px; }

.task-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }

.task-item {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}

/* タスクの1行目（サブタスク一覧はこの下に展開される） */
.task-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
}
.task-item.completed {
  opacity: 0.65;
  border-color: var(--green);
  background: rgba(111, 227, 165, 0.08);
}
.task-item.completed .task-name { text-decoration: line-through; color: var(--text-dim); }

.task-main { flex: 1; display: flex; flex-direction: column; gap: 6px; min-width: 0; }

/* ミッション名の隣に開閉トグル・進捗を添える1行目
   名前が長いときは名前側を折り返し、トグルと進捗は隣に残す（折り返して離れないように） */
.task-title-row {
  display: flex;
  align-items: center;
  gap: 4px;
}
.task-name { font-size: 15px; word-break: break-all; min-width: 0; }
/* トグル・進捗は縮めない */
.task-title-row .subtask-toggle,
.task-title-row .subtask-progress { flex-shrink: 0; }
/* 名前とくっつかないよう少し余白を足す */
.task-title-row .subtask-progress { margin-left: 4px; }

/* ===== カウンター式ミッション ===== */
.counter-box {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.btn-count {
  min-width: 32px;
  padding: 4px 8px;
  font-size: 15px;
  font-weight: 800;
  background: var(--bg-card);
  border: 1px solid var(--border);
}
.count-label {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-dim);
  min-width: 56px;
  text-align: center;
  white-space: nowrap;
}
.count-label.reached { color: var(--green); }
.count-bar {
  flex: 1 1 60px;
  height: 8px;
  min-width: 60px;
}
.count-fill { background: linear-gradient(90deg, var(--accent), var(--green)); }

/* ===== プリセット ===== */
.subsection-title {
  font-size: 14px;
  color: var(--text-dim);
  margin: 16px 0 12px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.preset-item { border-style: dashed; }
.preset-info {
  font-size: 12px;
  color: var(--text-dim);
}
/* 固定幅の列として扱う（+25 Pt でも +100 Pt でも列の開始位置が揃うように） */
.task-pt {
  font-size: 13px;
  font-weight: 700;
  color: var(--gold);
  white-space: nowrap;
  min-width: 58px;
  flex-shrink: 0;
}

.task-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* ===== ドラッグ&ドロップ並び替え ===== */
.drag-handle {
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 4px 2px;
  cursor: grab;
  flex-shrink: 0;
  touch-action: none; /* タッチでのスクロールを止めてドラッグを成立させる */
  opacity: 0.5;
  transition: opacity 0.15s ease, color 0.15s ease;
}
.drag-handle svg { width: 16px; height: 16px; display: block; }
.drag-handle:hover { opacity: 1; color: var(--text); }
.drag-handle:active { cursor: grabbing; }

/* 掴んでいる行 */
.task-item.dragging {
  opacity: 0.9;
  position: relative;
  z-index: 5;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.45);
  border-color: var(--accent);
  cursor: grabbing;
}
/* 並び替え中は他の行が入れ替わるのをなめらかに見せる */
.task-list.sorting .task-item:not(.dragging) {
  transition: transform 0.15s ease;
}
.task-list.sorting { user-select: none; }

.btn-complete { background: var(--accent-strong); }
.btn-undo { background: transparent; border: 1px solid var(--green); color: var(--green); }
.btn-icon {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 6px 8px;
  font-size: 13px;
}

/* アイコンボタン（正方形・SVG入り） */
.btn-sq { padding: 7px; }
.btn-sq svg { width: 16px; height: 16px; display: block; }
.btn-danger-hover:hover:not(:disabled) { color: var(--red); border-color: var(--red); }

/* ===== サブタスク ===== */
.subtask-toggle {
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 4px;
  cursor: pointer;
  transition: transform 0.15s ease;
  flex-shrink: 0;
}
.subtask-toggle svg { width: 16px; height: 16px; display: block; }
.subtask-toggle.open { transform: rotate(90deg); }
.subtask-toggle:hover { color: var(--text); }

/* タイトル行に並べるので、count-label の固定幅・中央寄せ(カウンター用)を解除 */
.subtask-progress { font-size: 12px; text-align: left; min-width: 0; }

.subtask-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 2px 0 2px 20px;
}
/* ハンドル＋チェックボックスの行 */
.subtask-item {
  display: flex;
  align-items: center;
  gap: 4px;
}
.subtask-item label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  cursor: pointer;
}
/* サブタスクのハンドルは少し小さめに */
.subtask-list .drag-handle svg,
.subtask-edit-item .drag-handle svg { width: 14px; height: 14px; }
/* 掴んでいるサブタスク行 */
.subtask-item.dragging,
.subtask-edit-item.dragging {
  opacity: 0.9;
  position: relative;
  z-index: 5;
  cursor: grabbing;
}
.subtask-list.sorting,
.subtask-edit-list.sorting { user-select: none; }
.subtask-item input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--green);
  cursor: pointer;
}
.subtask-name.done { text-decoration: line-through; color: var(--text-dim); }

/* フォーム内のサブタスク編集 */
.subtask-editor { margin-top: 12px; }
.subtask-editor-label { font-size: 12px; color: var(--text-dim); margin-bottom: 8px; }
.subtask-edit-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 8px;
}
.subtask-edit-item { display: flex; gap: 6px; }
.subtask-edit-item input { flex: 1; }
.subtask-add-row { display: flex; gap: 6px; }
.subtask-add-row input { flex: 1; }

.task-empty { color: var(--text-dim); font-size: 14px; text-align: center; padding: 12px 0; }

/* ===== タスクフォーム ===== */
.type-toggle { display: flex; gap: 14px; margin-bottom: 12px; flex-wrap: wrap; }
.type-option {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: var(--text-dim);
  cursor: pointer;
}
.type-option input { accent-color: var(--accent); }
.type-option:has(input:checked) { color: var(--text); }

.task-form { display: flex; gap: 8px; flex-wrap: wrap; }
.task-form input[type="text"] { flex: 1 1 200px; }
.task-form select { flex: 0 0 110px; }
.target-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-dim);
}
.target-label input { width: 80px; }
/* 日付・時刻入力は中身＋アイコンが収まる幅を確保（80pxだと見切れる） */
.target-label input[type="date"] { width: auto; min-width: 165px; }
.target-label input[type="time"] { width: auto; min-width: 120px; }
.form-buttons { display: flex; gap: 8px; }

/* ===== レベルアップ演出 ===== */
.levelup-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 12, 24, 0.7);
  z-index: 100;
  animation: fadeIn 0.25s ease;
}
.levelup-box {
  text-align: center;
  animation: popIn 0.5s cubic-bezier(0.18, 1.4, 0.4, 1);
}
.levelup-title {
  font-size: 42px;
  font-weight: 900;
  letter-spacing: 4px;
  background: linear-gradient(90deg, var(--gold), var(--pink), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 30px rgba(255, 209, 102, 0.35);
}
.levelup-level { font-size: 28px; font-weight: 800; margin-top: 10px; color: var(--text); }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn {
  0% { transform: scale(0.3); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

/* ===== トースト ===== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 10px 20px;
  font-size: 14px;
  z-index: 90;
  animation: fadeIn 0.2s ease;
  max-width: 90vw;
}

@media (max-width: 480px) {
  .level-row { flex-direction: column; align-items: stretch; }
  .level-badge { align-self: center; }
}

/* ===== 付箋メモ ===== */
.notes-card { margin-bottom: 0; }

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

/* 付箋1枚：角丸カード＋左端のアクセントラインで「付箋らしさ」を出す */
.note-item {
  position: relative;
  display: flex;
  align-items: flex-start; /* 複数行になってもハンドルは上寄せで固定 */
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.18);
}

.note-item .drag-handle { padding: 12px 2px 12px 4px; }

.note-text {
  display: block;
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.6;
  padding: 10px 34px 10px 4px; /* 右は削除ボタンぶん空ける（左はハンドルぶん） */
  min-height: 64px;
  overflow: hidden; /* 高さは自動で伸ばすのでスクロールバーは出さない */
}
.note-text::placeholder { color: var(--text-dim); }
.note-item:focus-within { border-color: var(--accent); }

.note-del {
  position: absolute;
  top: 6px;
  right: 6px;
}

/* 掴んでいる付箋（ミッションと同じ見え方に揃える） */
.note-item.dragging {
  opacity: 0.9;
  z-index: 5;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.45);
  border-color: var(--accent);
  cursor: grabbing;
}
.note-list.sorting { user-select: none; }
.note-list.sorting .note-item:not(.dragging) {
  transition: transform 0.15s ease;
}
