:root {
  color-scheme: light dark;
  --bg: #f7f7f5;
  --surface: #ffffff;
  --text: #1f1f1d;
  --text-sub: #66665f;
  --text-faint: #8d8d85;
  --line: #e4e4de;
  --line-strong: #c9c9c1;
  --accent: #1f6fb2;
  --on-accent: #ffffff;
  --accent-bg: #e6f1fb;
  --accent-text: #0c447c;
  --danger: #b3261e;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1b1a;
    --surface: #262624;
    --text: #f0f0ec;
    --text-sub: #b0b0a8;
    --text-faint: #85857d;
    --line: #3a3a37;
    --line-strong: #52524e;
    --accent: #5aa5e6;
    --on-accent: #0b2238;
    --accent-bg: #16385a;
    --accent-text: #cfe5fa;
    --danger: #f2877f;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

button {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
button.small { padding: 5px 10px; font-size: 13px; min-height: 32px; }
button:disabled { opacity: 0.6; cursor: default; }

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 10px) 16px calc(env(safe-area-inset-bottom) + 150px);
}

.notice {
  margin: 0 0 10px;
  padding: 8px 10px;
  font-size: 13px;
  color: var(--text-sub);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.notice.warn { color: var(--danger); }

.head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 4px 0 10px; }
.head-title { display: flex; align-items: baseline; gap: 8px; min-width: 0; flex-wrap: wrap; }
.head h1 { margin: 0; font-size: 20px; font-weight: 600; }
.relative { font-size: 13px; color: var(--text-sub); }
.head-actions { display: flex; gap: 4px; flex: none; }

.week { display: grid; grid-template-columns: 28px repeat(7, minmax(0, 1fr)) 28px; gap: 2px; align-items: center; margin-bottom: 12px; }
.week button { background: transparent; border: 1px solid transparent; padding: 5px 0; min-height: 44px; }
.week .arrow { color: var(--text-sub); font-size: 18px; }
.day small { display: block; font-size: 11px; color: var(--text-sub); }
.day b { display: block; font-size: 15px; font-weight: 600; }
.day i { display: block; width: 4px; height: 4px; margin: 2px auto 0; border-radius: 50%; }
.day.has i { background: var(--text-sub); }
.day.today:not(.on) b { color: var(--accent); }
.week .day.on { background: var(--accent-bg); border-color: var(--accent); }
.day.on b, .day.on small { color: var(--accent-text); }

.label { margin: 16px 0 6px; font-size: 12px; font-weight: 600; color: var(--text-sub); }
.main > .section:first-child > .label { margin-top: 0; }
.empty { margin: 0; padding: 6px 0; font-size: 13px; color: var(--text-faint); }

.event { display: flex; align-items: center; gap: 10px; padding: 8px 10px; margin-bottom: 6px; border-radius: 8px; background: var(--accent-bg); color: var(--accent-text); font-size: 14px; }
.event time { flex: none; font-size: 12px; }

.task { display: flex; align-items: center; gap: 12px; min-height: 44px; border-bottom: 1px solid var(--line); }
.task label { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; min-height: 44px; padding: 6px 0; cursor: pointer; }
.task input { flex: none; width: 20px; height: 20px; margin: 0; accent-color: var(--accent); }
.task .name { min-width: 0; overflow-wrap: anywhere; }
.task.done .name { text-decoration: line-through; color: var(--text-faint); }
.task .meta { flex: none; font-size: 12px; color: var(--text-sub); }
.task .meta.late { color: var(--danger); }
.task .remove { flex: none; width: 36px; height: 44px; margin-right: -8px; border: 0; background: transparent; color: var(--text-faint); font-size: 16px; }

.composer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 10px 16px calc(env(safe-area-inset-bottom) + 10px);
  background: var(--bg);
  border-top: 1px solid var(--line);
}
.composer > * { max-width: 528px; margin-left: auto; margin-right: auto; }
.composer-form { display: flex; gap: 8px; }
.composer-form input {
  flex: 1;
  min-width: 0;
  height: 44px;
  padding: 0 12px;
  font: inherit;
  font-size: 16px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
}
.composer-form input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.composer-form button { flex: none; width: 44px; height: 44px; padding: 0; display: flex; align-items: center; justify-content: center; }

.preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  padding: 8px 10px;
  font-size: 13px;
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: 8px;
}
.preview span { min-width: 0; overflow-wrap: anywhere; }
.preview button { flex: none; }

.error { margin: 6px 2px 0; font-size: 13px; color: var(--danger); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 76px);
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: calc(100% - 32px);
  padding: 8px 12px;
  font-size: 13px;
  color: var(--bg);
  background: var(--text);
  border-radius: 8px;
  white-space: nowrap;
}
.toast button { padding: 2px 6px; font-size: 13px; color: inherit; background: transparent; border: 1px solid currentColor; }

.login { max-width: 360px; margin: 0 auto; padding: 96px 24px; text-align: center; }
.login h1 { margin: 0 0 8px; font-size: 24px; font-weight: 600; }
.login p { color: var(--text-sub); }
.login button { width: 100%; min-height: 44px; margin-top: 12px; }

@media (min-width: 860px) {
  .app { max-width: 900px; }
  .composer > * { max-width: 868px; }
  .main.split { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); gap: 32px; }
  .main.split > .section:nth-child(2) > .section:first-child > .label { margin-top: 0; }
}
