:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --text: #1f2328;
  --muted: #687280;
  --line: #e3e6ea;
  --accent: #2f6fdb;
  --accent-soft: #e6eefc;
  --high: #d9473f;
  --mid: #d99a1e;
  --low: #3a9a5b;
  --danger: #c93a32;
  --hour: 64px;
  --radius: 8px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171a;
    --panel: #1d2024;
    --text: #e6e8eb;
    --muted: #9aa3ad;
    --line: #2e3238;
    --accent: #6c9cf0;
    --accent-soft: #23314a;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

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

input, select, textarea {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
}

button {
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 6px 12px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}
button.ghost { background: transparent; border-color: var(--line); color: var(--text); }
button.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 18px; margin: 0; }
.datenav { display: flex; gap: 6px; align-items: center; }
.datenav button:not(.ghost) { background: transparent; color: var(--text); border-color: var(--line); padding: 6px 10px; }

.layout {
  display: grid;
  grid-template-columns: minmax(300px, 420px) 1fr;
  gap: 16px;
  padding: 16px 20px;
  max-width: 1280px;
  margin: 0 auto;
}
@media (max-width: 800px) {
  .layout { grid-template-columns: 1fr; }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  min-width: 0;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.panel-head h2 { font-size: 15px; margin: 0; }
.toggle, .summary, .hint { color: var(--muted); font-size: 12px; }

.add-form { display: grid; gap: 8px; margin-bottom: 12px; }
.add-form > input { width: 100%; }
.add-row { display: flex; gap: 6px; flex-wrap: wrap; align-items: end; }
.add-row > * { flex: 1 1 auto; }
.add-row button { flex: 0 0 auto; }
.due-field {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted, #666);
  white-space: nowrap;
}
.due-field input { flex: 1 1 auto; min-width: 0; }

.todo-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.todo {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--mid);
  border-radius: 6px;
  cursor: grab;
  background: var(--panel);
}
.todo.high { border-left-color: var(--high); }
.todo.low { border-left-color: var(--low); }
.todo.done { opacity: .55; }
.todo.done .title { text-decoration: line-through; }
.todo.dragging { opacity: .4; }
.todo .title { background: none; border: 0; padding: 0; color: var(--text); text-align: left; cursor: pointer; overflow-wrap: anywhere; }
.todo .meta { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.todo .meta .overdue { color: var(--danger); }
.todo .meta .planned { color: var(--accent); }
.todo .add-btn { background: var(--accent-soft); color: var(--accent); padding: 2px 10px; font-size: 16px; }
.empty { color: var(--muted); text-align: center; padding: 16px 0; }

.timeline {
  position: relative;
  display: grid;
  grid-template-columns: 52px 1fr;
  max-height: calc(100vh - 150px);
  overflow-y: auto;
  border-top: 1px solid var(--line);
}
.hours div {
  height: var(--hour);
  font-size: 11px;
  color: var(--muted);
  text-align: right;
  padding-right: 8px;
  transform: translateY(-7px);
}
.lane {
  position: relative;
  background-image:
    linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(color-mix(in srgb, var(--line) 50%, transparent) 1px, transparent 1px);
  background-size: 100% var(--hour), 100% calc(var(--hour) / 2);
}
.lane.drop-target { background-color: var(--accent-soft); }

.block {
  position: absolute;
  border-radius: 6px;
  padding: 4px 8px;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-left-width: 4px;
  overflow: hidden;
  cursor: move;
  touch-action: none;
  user-select: none;
  font-size: 12px;
}
.block.high { border-left-color: var(--high); }
.block.low { border-left-color: var(--low); }
.block.done { opacity: .55; }
.block.done .b-title { text-decoration: line-through; }
.block.active { box-shadow: 0 4px 14px rgba(0, 0, 0, .2); z-index: 5; }
.block .b-head { display: flex; gap: 6px; align-items: start; }
.block .b-title { flex: 1; font-weight: 600; overflow-wrap: anywhere; }
.block .b-time { color: var(--muted); }
.block .b-remove { background: none; color: var(--muted); padding: 0 4px; line-height: 1; }
.block .resize { position: absolute; left: 0; right: 0; bottom: 0; height: 8px; cursor: ns-resize; }

.now-line { position: absolute; left: 0; right: 0; height: 2px; background: var(--danger); z-index: 6; pointer-events: none; }
.now-line::before { content: ""; position: absolute; left: -4px; top: -3px; width: 8px; height: 8px; border-radius: 50%; background: var(--danger); }

dialog {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  width: min(520px, 92vw);
}
dialog::backdrop { background: rgba(0, 0, 0, .35); }
dialog form { display: grid; gap: 10px; }
dialog h3 { margin: 0 0 4px; }
dialog label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
dialog label > * { color: var(--text); font-size: 14px; }
.dialog-actions { display: flex; gap: 8px; margin-top: 6px; }
.spacer { flex: 1; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: #222;
  color: #fff;
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 13px;
}
