:root {
  --bg: #fff6ea;
  --surface: #ffffff;
  --text: #3b2f28;
  --muted: #9a8a7e;
  --line: #f0e3d4;
  --accent: #f08a4b;
  --accent-ink: #ffffff;
  --today: #e88a1a;
  --overdue: #d9443b;
  --danger-soft: #ffd9d4;
  --shadow: 0 2px 8px rgba(120, 80, 40, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1f1a17;
    --surface: #2b2420;
    --text: #f3e9e1;
    --muted: #a8988c;
    --line: #3a312b;
    --accent: #f39a62;
    --accent-ink: #1f1a17;
    --today: #f5a742;
    --overdue: #ff6b61;
    --danger-soft: #5a2a26;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", sans-serif;
  max-width: 560px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 16px calc(24px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}

button, input { font: inherit; color: inherit; }

/* ---- キャラクター ---- */
.hero {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 0 8px;
}

.character {
  width: 148px;
  height: 148px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--shadow);
  border: 4px solid var(--surface);
  transition: transform 0.25s ease;
}

.character img, .character video { width: 100%; height: 100%; object-fit: cover; display: block; }
.character video[hidden], .character img[hidden] { display: none; }
.character.bounce { animation: bounce 0.6s ease; }

@keyframes bounce {
  0%, 100% { transform: scale(1); }
  30% { transform: scale(1.12) rotate(-4deg); }
  60% { transform: scale(0.97) rotate(3deg); }
}

.bubble {
  margin: 10px 0 0;
  padding: 6px 14px;
  background: var(--surface);
  border-radius: 999px;
  font-size: 14px;
  box-shadow: var(--shadow);
  min-height: 1em;
}

.logout {
  position: absolute;
  top: 12px;
  right: 0;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 12px;
  padding: 6px;
  cursor: pointer;
}

/* ---- 追加欄 ---- */
.add {
  background: var(--surface);
  border-radius: 16px;
  padding: 10px;
  box-shadow: var(--shadow);
  margin-top: 8px;
}

.add input[type="text"] {
  width: 100%;
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 16px; /* iOS の自動ズーム防止 */
  outline: none;
}

.add input[type="text"]:focus { border-color: var(--accent); }

.add-row {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  align-items: stretch;
}

.add-row .add-assignee { flex: 1; min-width: 0; }

.add-btn {
  border: none;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
  border-radius: 10px;
  padding: 0 18px;
  cursor: pointer;
}

/* ---- カレンダーマーク ---- */
.date-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-width: 44px;
  min-height: 44px;
  padding: 0 8px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  flex-shrink: 0;
  justify-content: center;
}

/* ---- カレンダー（画面下から出るシート） ---- */
.picker {
  position: fixed;
  inset: 0;
  background: rgba(30, 20, 15, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 30;
}

.picker[hidden] { display: none; }

.picker-sheet {
  width: 100%;
  max-width: 560px;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
  animation: sheet-up 0.2s ease;
}

@keyframes sheet-up {
  from { transform: translateY(40px); opacity: 0; }
}

.picker-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.picker-title { font-size: 17px; font-weight: 700; }

.picker-nav {
  width: 44px;
  height: 44px;
  border: none;
  background: none;
  font-size: 26px;
  color: var(--accent);
  cursor: pointer;
}

.picker-week, .picker-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
}

.picker-week { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.picker-week span:first-child { color: var(--overdue); }
.picker-week span:last-child { color: #4a7fd4; }

.picker-grid { row-gap: 4px; }

.picker-day {
  height: 44px;
  border: none;
  border-radius: 50%;
  background: none;
  font-size: 16px;
  cursor: pointer;
  justify-self: center;
  width: 44px;
}

.picker-day.sun { color: var(--overdue); }
.picker-day.sat { color: #4a7fd4; }
.picker-day.is-today { box-shadow: inset 0 0 0 2px var(--accent); font-weight: 700; }
.picker-day.is-selected { background: var(--accent); color: var(--accent-ink); font-weight: 700; }

.picker-foot {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 10px;
}

.picker-foot button {
  flex: 1;
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: transparent;
  font-weight: 700;
  cursor: pointer;
}

.cal {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

.date-text { font-size: 13px; white-space: nowrap; }
.date-text:empty { display: none; }

.date-btn.has-date { color: var(--text); }
.date-btn.today { color: var(--today); border-color: var(--today); font-weight: 700; }
.date-btn.overdue { color: var(--overdue); border-color: var(--overdue); font-weight: 700; }

/* ---- 一覧 ---- */
.count {
  margin: 18px 4px 6px;
  font-size: 13px;
  color: var(--muted);
}

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

.task {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border-radius: 14px;
  padding: 8px 8px 8px 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none; /* iOS の長押しメニューを出さない */
  touch-action: pan-y;
}

/* 長押しの進み具合を左から塗る */
.task::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--danger-soft);
  transform: scaleX(0);
  transform-origin: left;
  z-index: 0;
}

.task.pressing::before { transform: scaleX(1); transition: transform 0.6s linear; }
.task.armed::before { transform: scaleX(1); background: var(--overdue); opacity: 0.35; }
.task > * { position: relative; z-index: 1; }

.task.leaving { animation: leave 0.3s ease forwards; }

@keyframes leave {
  to { opacity: 0; transform: translateX(40px); }
}

.task.entering { animation: enter 0.35s ease; }

@keyframes enter {
  from { opacity: 0; transform: translateY(-8px); background: #fff0dc; }
}

.task-main {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.task-title {
  font-size: 16px;
  overflow-wrap: anywhere;
}

.task-assignee {
  flex-shrink: 0;
  font-size: 12px;
  color: var(--muted);
  background: var(--bg);
  border-radius: 999px;
  padding: 2px 8px;
  margin-left: auto;
}

.task-assignee:empty { display: none; }

.empty, .hint {
  text-align: center;
  color: var(--muted);
}

.empty { margin: 24px 0; }
.hint { font-size: 12px; margin-top: 18px; }

/* ---- 元に戻す ---- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: #3b2f28;
  color: #fff;
  border-radius: 999px;
  padding: 8px 8px 8px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
  max-width: calc(100% - 32px);
  z-index: 10;
}

.toast[hidden] { display: none; }

.toast button {
  border: none;
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  padding: 6px 14px;
  font-weight: 700;
  cursor: pointer;
}

/* ---- 0件の演出 ---- */
.celebrate {
  position: fixed;
  inset: 0;
  background: rgba(30, 20, 15, 0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 20;
  color: #fff;
}

.celebrate[hidden] { display: none; }

.celebrate-title {
  margin: 0 0 14px;
  font-size: 28px;
  font-weight: 800;
  color: #ffd36b;
  letter-spacing: 0.04em;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
}

.celebrate video {
  max-width: 100%;
  max-height: 68vh;
  border-radius: 16px;
}

.celebrate-close { font-size: 13px; opacity: 0.7; margin-top: 16px; }

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