:root {
  color-scheme: light dark;
  --bg: #eef1f7;
  --bg-accent: #e4e9fb;
  --panel-bg: #ffffff;
  --text: #1b2030;
  --muted: #6b7280;
  --border: #e6e9f0;
  --accent: #4f6df5;
  --accent-hover: #3b57d6;
  --accent-soft: #eef1ff;
  --danger: #e0524f;
  --done: #9ca3af;
  --success: #1f9d55;
  --shadow: 0 1px 2px rgba(20, 24, 38, 0.04), 0 10px 28px rgba(20, 24, 38, 0.06);
  --shadow-hover: 0 2px 4px rgba(20, 24, 38, 0.06), 0 14px 32px rgba(20, 24, 38, 0.09);

  --accent-notes: #4f6df5;
  --accent-tasks: #e0973f;
  --accent-routine: #8b5cf6;
  --accent-wake: #14b8a6;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10121a;
    --bg-accent: #171a2a;
    --panel-bg: #1a1d28;
    --text: #e8eaf0;
    --muted: #9aa0ac;
    --border: #292d3a;
    --accent: #7b91ff;
    --accent-hover: #94a6ff;
    --accent-soft: #232a44;
    --danger: #f07572;
    --done: #6b7280;
    --success: #3ecb7a;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.25), 0 10px 28px rgba(0, 0, 0, 0.36);
    --shadow-hover: 0 2px 4px rgba(0, 0, 0, 0.3), 0 16px 36px rgba(0, 0, 0, 0.42);

    --accent-notes: #7b91ff;
    --accent-tasks: #f0ad5c;
    --accent-routine: #a685fa;
    --accent-wake: #2dd4bf;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Hiragino Sans", "Yu Gothic UI", "Segoe UI", system-ui, sans-serif;
  background:
    radial-gradient(720px 320px at 12% -8%, var(--bg-accent), transparent 60%),
    var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 1080px;
  margin: 0 auto;
  padding: 40px 20px 80px;
}

.app-header {
  margin-bottom: 28px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.app-header h1 {
  font-size: 1.85rem;
  font-weight: 800;
  margin: 0 0 6px;
  letter-spacing: -0.01em;
}

.app-subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

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

.card {
  position: relative;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--card-accent, var(--accent));
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-hover);
}

.card:nth-child(1) { --card-accent: var(--accent-notes); }
.card:nth-child(2) { --card-accent: var(--accent-tasks); }
.card:nth-child(3) { --card-accent: var(--accent-tasks); }
.card:nth-child(4) { --card-accent: var(--accent-routine); }

.card-label {
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 500;
}

.card-value {
  font-size: 1.8rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

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

@media (max-width: 760px) {
  .dashboard { grid-template-columns: repeat(2, 1fr); }
  .grid { grid-template-columns: 1fr; }
  .form-row { flex-direction: column; align-items: stretch !important; }
  .habit-label { width: 96px; }
}

.panel {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 24px;
  box-shadow: var(--shadow);
}

.panel-notes { --panel-accent: var(--accent-notes); }
.panel-tasks { --panel-accent: var(--accent-tasks); }
.panel-routine { --panel-accent: var(--accent-routine); }
.panel-wake { --panel-accent: var(--accent-wake); }

.panel-wide {
  margin-bottom: 20px;
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

.panel-head h2 {
  margin: 0;
}

.hint {
  font-size: 0.78rem;
  color: var(--muted);
}

.panel h2 {
  font-size: 1.04rem;
  margin: 0 0 14px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 9px;
  letter-spacing: -0.01em;
}

.panel h2::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--panel-accent, var(--accent));
  flex-shrink: 0;
}

.panel h3 {
  font-size: 0.86rem;
  margin: 26px 0 12px;
  color: var(--muted);
  font-weight: 600;
}

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

.form-inline {
  flex-direction: row;
  align-items: flex-start;
}

.form-inline input {
  flex: 1;
}

.form-row {
  flex-direction: row;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.78rem;
  color: var(--muted);
}

.form input,
.form textarea {
  font: inherit;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  resize: vertical;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form input:focus,
.form textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.form-spacer {
  visibility: hidden;
  pointer-events: none;
}

.form button {
  align-self: flex-start;
  font: inherit;
  font-weight: 700;
  padding: 10px 20px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease, transform 0.1s ease;
}

.form button:hover {
  background: var(--accent-hover);
}

.form button:active {
  transform: translateY(1px);
}

.error {
  color: var(--danger);
  font-size: 0.85rem;
  min-height: 1.1em;
  margin: 4px 0 0;
}

.list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 420px;
  overflow-y: auto;
}

.list-empty {
  color: var(--muted);
  font-size: 0.88rem;
  padding: 12px 2px;
  margin: 0;
}

.note-item, .task-item, .sleep-item {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 14px;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.note-item:hover, .task-item:hover, .sleep-item:hover {
  border-color: color-mix(in srgb, var(--accent) 35%, var(--border));
  background: var(--accent-soft);
}

.note-item .item-title {
  font-weight: 700;
  margin-bottom: 4px;
}

.note-item .item-body {
  white-space: pre-wrap;
  font-size: 0.9rem;
  margin-bottom: 6px;
  color: var(--text);
}

.item-meta {
  font-size: 0.75rem;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.task-item {
  display: flex;
  align-items: center;
  gap: 10px;
}

.task-item .task-title {
  flex: 1;
}

.task-item.done .task-title {
  text-decoration: line-through;
  color: var(--done);
}

.task-item .status-badge {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  white-space: nowrap;
}

.task-item.done .status-badge {
  color: var(--success);
  border-color: var(--success);
}

.icon-btn {
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--muted);
  font-size: 0.82rem;
  padding: 5px 10px;
  border-radius: 8px;
  white-space: nowrap;
  transition: background 0.15s ease, color 0.15s ease;
}

.icon-btn:hover {
  background: var(--border);
}

.icon-btn.delete:hover {
  color: var(--danger);
}

input[type="checkbox"] {
  accent-color: var(--accent);
  width: 17px;
  height: 17px;
  flex-shrink: 0;
}

/* ---- 起床記録一覧 ---- */

.sleep-item {
  display: flex;
  align-items: center;
  gap: 14px;
}

.sleep-date {
  font-size: 0.8rem;
  color: var(--muted);
  min-width: 84px;
}

.sleep-times {
  flex: 1;
  font-weight: 700;
  color: var(--accent-wake);
}

/* ---- チャート ---- */

.chart-box {
  overflow-x: auto;
  padding-bottom: 4px;
}

.chart-svg {
  display: block;
  width: 100%;
  min-width: 260px;
  height: auto;
}

.chart-legend {
  display: flex;
  gap: 16px;
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 4px;
}

.chart-legend i {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 999px;
  margin-right: 5px;
  vertical-align: middle;
}

/* ---- 習慣グリッド ---- */

.habit-grid {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
}

.habit-row {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 0;
}

.habit-row + .habit-row {
  border-top: 1px solid var(--border);
}

.habit-header {
  border-top: none;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2px;
}

.habit-label {
  width: 140px;
  flex-shrink: 0;
  font-size: 0.85rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.habit-cell {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  border-radius: 999px;
  background: var(--border);
  opacity: 0.6;
  transition: transform 0.1s ease;
}

.habit-cell.done {
  background: var(--accent-routine);
  opacity: 1;
}

.habit-date-label {
  width: 18px;
  height: auto;
  background: none;
  opacity: 1;
  font-size: 0.68rem;
  color: var(--muted);
  text-align: center;
  writing-mode: vertical-rl;
}
